🤖 AI Math Unit 4 — Probabilistic Machine LearningApplied STEM · Joint and conditional probability P(A|B) · Bayes' Theorem: Prior, Likelihood, Posterior · Total probability theorem · Naive Bayes independence assumption · Text spam filtering & medical diagnostics
Uncertainty is omnipresent in real-world data. Bayes' Theorem provides the mathematical framework for updating beliefs when observing new evidence, forming the core of Bayesian machine learning and Naive Bayes classifiers.
▲ Theorem 4.1 — Bayes' Theorem in Machine Learning
For hypothesis (class) C C and observed evidence (features) xx: \[ P(C | \mathbf{x}) = \frac{P(\mathbf{x} | C) P(C)}{P(\mathbf{x})} \] Where: • \( P(C) \) is the Prior probability of class \( C \). • \( P(\mathbf{x} | C) \) is the Likelihood of observing features \( \mathbf{x} \) given class \( C \). • \( P(\mathbf{x}) = \sum_k P(\mathbf{x}|C_k)P(C_k) \) is the Marginal probability (Evidence). • \( P(C | \mathbf{x}) \) is the Posterior probability.
التحديث البايزي للمعتقدات الاحتمالية: في نماذج الذكاء الاصطناعي الإحصائية، تحدّث قاعدة بايز \(P(y \mid \mathbf{x}) = \frac{P(\mathbf{x} \mid y)P(y)}{P(\mathbf{x})}\) الاحتمال القبلي للفئة \(P(y)\) في ضوء معقولية المشاهدة \(P(\mathbf{x} \mid y)\)، مقسوماً على الاحتمال الكلي للدليل \(P(\mathbf{x}) = \sum_{c} P(\mathbf{x} \mid c)P(c)\).
شجرة احتمالات بايزية من مرحلتين توضح كيف يؤدي انخفاض الاحتمال القبلي \(P(D) = 0.02\) إلى احتمال بعدي \(P(D \mid +) = \frac{0.019}{0.019 + 0.049} \approx 0.279\).
⊙ مستكشف تفاعلي · مصنف نظرية بايز: الاحتمال القبلي مقابل الاحتمال البعدي P(C₁ | +) \(P(C_{1} | +)\)
تفاعلي
جدول عددي حي لـ Bayes' نظرية Classifier: Prior القاعدة معدل vs. Posterior \(P(C_{1} | +)\)
مع ثابت sensitivity \(P(+ | C_{1}) = 0.90\)، see كيف low القاعدة معدل \(P(C_{1})\) أو high خطأ-موجب معدل \(P(+ | C_{0})\) dramatically يختزل posterior احتمال \(P(C_{1} | +)\).
جدول التوافق التجريبي لـ \(N = 1000\) رسالة بريدية يعطي الاحتمالات الشرطية \(P(\text{'free'}\mid \text{Spam}) = 0.80\) مقابل \(P(\text{'free'}\mid \text{Ham}) = 0.10\).
Prevents zero الاحتمال: \(\frac{\text{count} + 1}{\text{total} + |V|}\)
◆ لماذا تعمل القاعدة — الاشتقاق من الاحتمال المشترك والاحتمال الكلي
تماثل الاحتمال المشترك: من تعريف الاحتمال الشرطي لدينا \(P(A \cap B) = P(A \mid B)P(B) = P(B \mid A)P(A)\). وبقسمة الطرفين على \(P(B) > 0\) وفك المقام بقانون الاحتمال الكلي \(B = (B \cap A) \cup (B \cap \neg A)\) نحصل على \[ P(A \mid B) = \frac{P(B \mid A)P(A)}{P(B \mid A)P(A) + P(B \mid \neg A)P(\neg A)}. \]
Worked Example 4.A — Bayesian Spam Classification
المسألة. An email filter processes emails where \( 20\% \) are spam (\( P(S) = 0.20 \)) and \( 80\% \) are legitimate (\( P(L) = 0.80 \)). The word 'lottery' appears in \( 60\% \) of spam emails (\( P(W|S) = 0.60 \)) and in \( 1\% \) of legitimate emails (\( P(W|L) = 0.01 \)). If an incoming email contains the word 'lottery', what is the probability that it is spam?
▸ عرض خطوات الحل بالتفصيل
By Bayes' Theorem: \[ P(S|W) = \frac{P(W|S)P(S)}{P(W)} \] Calculate total probability \( P(W) \): \[ P(W) = P(W|S)P(S) + P(W|L)P(L) = (0.60)(0.20) + (0.01)(0.80) = 0.12 + 0.008 = 0.128 \] Compute posterior: \[ P(S|W) = \frac{0.12}{0.128} = \frac{120}{128} = \frac{15}{16} = 0.9375 \]. Despite only 20% of all emails being spam initially, observing the word 'lottery' raises the probability to \( 93.75\% \). Answer: \( 93.75\% \) (or \( 0.938 \)).
Worked Example \(B\) — Conditional Probability, Bayes' Rule & Classifiers (Medium Application)
المسألة. Given \( n = 4 \) independent observations from a normal distribution with sum \( \sum_{i=1}^{4} x_i = 12 \), what is the Maximum Likelihood Estimate (MLE) \( \hat{\mu}_{\text{MLE}} \)?
Worked Example \(C\) — Conditional Probability, Bayes' Rule & Classifiers (Hard Application)
المسألة. A logistic regression model produces a class probability \( p = P(y=1|\mathbf{x}) = 0.40 \). Compute the corresponding log-odds (logit) \( \ln\left(\frac{p}{1-p}\right) \).
Worked Example \(D\) — Conditional Probability, Bayes' Rule & Classifiers (Easy Application)
المسألة. A medical diagnostic test for a rare disease is designed to be highly sensitive and specific. The disease affects \( 1 \) in every \( 1000 \) individuals in the population. The test has a sensitivity of \( 99 \)\% (meaning it correctly identifies \( 99 \)\% of individuals who have the disease) and a specificity of \( 95 \)\% (meaning it correctly identifies \( 95 \)\% of individuals who do not have the disease). If a randomly selected individual from the population tests positive, what is the probability that they actually have the disease?
▸ عرض خطوات الحل بالتفصيل
Let D be the event that an individual has the disease, and P be the event that the individual tests positive.
We are given the following probabilities:
- Prior probability of having the disease: \(P(D) = \frac{1}{1000} = 0.001\)
- Prior probability of not having the disease: \(P(D^c) = 1 - P(D) = 1 - 0.001 = 0.999\)
- Sensitivity (true positive rate): \(P(P|D) = 0.99\)
- Specificity (true negative rate): \(P(P^c|D^c) = 0.95\)
From specificity, we can derive the false positive rate: \(P(P|D^c) = 1 - P(P^c|D^c) = 1 - 0.95 = 0.05\).
We want to find the probability that an individual actually has the disease given a positive test result, which is \(P(D|P)\). We can use Bayes' Theorem:
\[P(D|P) = \frac{P(P|D) P(D)}{P(P)}\]
To find \(P(P)\), the overall probability of testing positive, we can use the law of total probability:
\[P(P) = P(P|D) P(D) + P(P|D^c) P(D^c)\]
Substitute the given values:
\[P(P) = (0.99)(0.001) + (0.05)(0.999)\]
\[P(P) = 0.00099 + 0.04995\]
\[P(P) = 0.05094\]
Now, substitute \(P(P)\) back into Bayes' Theorem:
\[P(D|P) = \frac{(0.99)(0.001)}{0.05094}\]
\[P(D|P) = \frac{0.00099}{0.05094}\]
\[P(D|P) \approx 0.0194346\]
Therefore, the probability that a person who tests positive actually has the disease is approximately \( 0.0194 \), which is closest to \( 0.019 \).
⚠️ أخطاء شائعة في الاختبار — إهمال المعدل الأساسي وعكس الشرط
1. الخلط بين \(P(+ \mid D)\) و\(P(D \mid +)\): حساسية الاختبار البالغة \(99\%\) لا تعني أن احتمال الإصابة عند ظهور نتيجة موجبة هو \(99\%\) إذا كان انتشار المرض \(P(D)\) نادراً. 2. نسيان حد الإيجابيات الكاذبة في المقام: احسب المقام الكلي دائماً \(P(+) = P(+\mid D)P(D) + P(+\mid \neg D)(1 - P(D))\) مع الانتباه إلى أن \(P(+\mid \neg D) = 1 - \text{Specificity}\).
Claiming \(+25\%\) followed by \(-25\%\) returns to \(100\%\)
The \(25\%\) reduction applies to the larger base \(1.25 Q_0\), not \(Q_0\).
Multiply scale factors: \(1.25 \times 0.75 = 0.9375\) (a \(6.25\%\) net decrease).
Solving \(-3x > 12\) as \(x > -4\)
يؤدي إلى فقدان جذور صحيحة أو إدخال جذور دخيلة لا تحقق المعادلة الأصلية.
Flip the inequality symbol whenever multiplying or dividing by a negative: \(x < -4\).
Computing round-trip average speed as \(\frac{v_1 + v_2}{2}\)
يؤدي إلى فقدان جذور صحيحة أو إدخال جذور دخيلة لا تحقق المعادلة الأصلية.
Use total distance over total time: \(v_{\text{avg}} = \frac{2v_1 v_2}{v_1 + v_2}\).
▲ استراتيجية الحل والتحقق السريع — الاحتمال الشرطي وقاعدة بايز
طريقة التكرارات الطبيعية (عينة من 10,000): حوّل النسب المئوية إلى أعداد صحيحة من أصل \(10{,}000\) حالة لحساب \(\text{TP}\) و\(\text{FP}\) مباشرة، ثم احسب \(P(D \mid +) = \frac{\text{TP}}{\text{TP} + \text{FP}}\) لتجنب أخطاء الفواصل العشرية.
[Practice 1 · Medium] A spam classification model identifies \( TP = 30 \) genuine spam emails and \( FP = 10 \) legitimate emails falsely flagged as spam. What is the precision of this model?
💡 Hint 1 of 3
Precision is the fraction of predicted positive instances that are truly positive: \(\text{Precision} = \frac{TP}{TP + FP}\).
💡 Hint 2 of 3
Substitute and simplify: \(\text{Precision} = \frac{30}{30 + 10}\).
💡 Hint 3 of 3
Compute the final value from: \(\frac{30}{30 + 10}\).
Precision is the fraction of predicted positive instances that are truly positive: \( \text{Precision} = \frac{TP}{TP + FP} = \frac{30}{30 + 10} = \frac{30}{40} = 75.0\% \).
[Practice 2 · Hard] Compute the Manhattan (\( L_1 \)) norm and Euclidean (\( L_2 \)) norm of the word vector \( \mathbf{w} = [10, -15]^T \).
💡 Hint 1 of 3
Set up the initial relation: \( L_1 \) norm is the sum of absolute values: \( |10| + |-15| = 25 \).
💡 Hint 2 of 3
Rewrite and simplify to obtain: \( L_2 \) norm is the square root of sum of squares: \(\sqrt{(10)^2 + (-15)^2}\). Rewrite and substitute: \(\sqrt{(10)^2 + (-15)^2} = \sqrt{100 + 225}\).
💡 Hint 3 of 3
Evaluate \(\sqrt{100 + 225}\) to obtain the final answer.
\( L_1 \) norm is the sum of absolute values: \( |10| + |-15| = 25 \). \( L_2 \) norm is the square root of sum of squares: \( \sqrt{(10)^2 + (-15)^2} = \sqrt{100 + 225} = \sqrt{325} \).
[Practice 3 · Easy] Consider two vectors, \( \mathbf{u} = \begin{bmatrix} 3 \\ 4 \end{bmatrix} \) and \( \mathbf{v} = \begin{bmatrix} 1 \\ -2 \end{bmatrix} \). What is the vector representing \( 2\mathbf{u} - \mathbf{v} \)?
💡 Hint 1 of 3
To find the vector \( 2\mathbf{u} - \mathbf{v} \), we first compute \( 2\mathbf{u} \) and then subtract \( \mathbf{v} \) from the result.
Therefore, the resulting vector is \(\begin{bmatrix} 5 \\ 10 \end{bmatrix}\).
To find the vector \( 2\mathbf{u} - \mathbf{v} \), we first compute \( 2\mathbf{u} \) and then subtract \( \mathbf{v} \) from the result.
\( 2\mathbf{u} = 2 \times \begin{bmatrix} 3 \\ 4 \end{bmatrix} = \begin{bmatrix} 2 \times 3 \\ 2 \times 4 \end{bmatrix} = \begin{bmatrix} 6 \\ 8 \end{bmatrix} \).
Now, we subtract \( \mathbf{v} \) from \( 2\mathbf{u} \):
\( 2\mathbf{u} - \mathbf{v} = \begin{bmatrix} 6 \\ 8 \end{bmatrix} - \begin{bmatrix} 1 \\ -2 \end{bmatrix} = \begin{bmatrix} 6 - 1 \\ 8 - (-2) \end{bmatrix} = \begin{bmatrix} 5 \\ 8 + 2 \end{bmatrix} = \begin{bmatrix} 5 \\ 10 \end{bmatrix} \).
Therefore, the resulting vector is \( \begin{bmatrix} 5 \\ 10 \end{bmatrix} \).
[Practice 4 · Medium] Consider a dataset of \( n \) observations \( (x_i, y_i) \) for \( i = 1, \dots, n \), where \( x_i \) are scalar predictor variables and \( y_i \) are scalar response variables. The ordinary least squares (OLS) estimates for the intercept \( \beta_0 \) and the slope \( \beta_1 \) of the linear model \( y = \beta_0 + \beta_1 x + \epsilon \) are given by \( \hat{\beta}_1 = \frac{\sum_{i=1}^n (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^n (x_i - \bar{x})^2} \) and \( \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \). Suppose we have a dataset where \( n = 5 \), \( \sum x_i = 15 \), \( \sum y_i = 30 \), \( \sum x_i^2 = 55 \), \( \sum y_i^2 = 210 \), and \( \sum x_i y_i = 105 \). A new data point \( (x_6, y_6) \) is added to the dataset. If the new regression line that minimizes the sum of squared errors for the \( n+1 = 6 \) points is parallel to the original regression line (i.e., \( \hat{\beta}_1^{\text{new}} = \hat{\beta}_1^{\text{old}} \)), what is the value of \( y_6 \) in terms of \( x_6 \)?
💡 Hint 1 of 3
For the original \( n = 5 \) observations, \( \bar{x} = \frac{15}{5} = 3 \) and \(\bar{y} = \frac{30}{5}\).
💡 Hint 2 of 3
The sums of squares are \( S_{xx} = 55 - 5(3^2) = 10 \) and \( S_{xy} = 105 - 5(3)(6) = 15 \), giving slope \( \hat{\beta}_1 = \frac{15}{10} = 1.5 \) and intercept \(\hat{\beta}_0 = 6 - 1.5(3)\).
💡 Hint 3 of 3
When a 6th point \((x_6, y_6)\) lying on the existing regression line \(y_6 = 1.5x_6 + 1.5\) is added, the residual is zero and the OLS slope remains unchanged at \(1.5\).
For the original \( n = 5 \) observations, \( \bar{x} = \frac{15}{5} = 3 \) and \( \bar{y} = \frac{30}{5} = 6 \). The sums of squares are \( S_{xx} = 55 - 5(3^2) = 10 \) and \( S_{xy} = 105 - 5(3)(6) = 15 \), giving slope \( \hat{\beta}_1 = \frac{15}{10} = 1.5 \) and intercept \( \hat{\beta}_0 = 6 - 1.5(3) = 1.5 \). When a 6th point \( (x_6, y_6) \) lying on the existing regression line \( y_6 = 1.5x_6 + 1.5 \) is added, the residual is zero and the OLS slope remains unchanged at \( 1.5 \).
[Practice 5 · Hard] Consider a dataset of \( n \) data points, where each data point is a vector in \( \mathbb{R}^{D} \). A non-linear dimensionality reduction technique maps these data points to a lower-dimensional space \( \mathbb{R}^{d} \). The mapping function for a single data point \( \mathbf{x} \in \mathbb{R}^{D} \) is given by \( f(\mathbf{x}) = \phi(\mathbf{x}) \), where \( \phi: \mathbb{R}^{D} \to \mathbb{R}^{d} \) is a function designed to preserve local neighborhood structures. Suppose the mapping \( \phi \) is defined by an explicit feature map \( \phi(\mathbf{x}) = [\mathbf{x}^T \mathbf{x}, \mathbf{x}^T \mathbf{x}, \dots, \mathbf{x}^T \mathbf{x}]^T \) where the vector \( \mathbf{x} \in \mathbb{R}^{10} \) and \( d \) is the dimension of the embedded space. If the goal is to embed these points into a space such that pairwise Euclidean distances are preserved as closely as possible under a specific distortion, and it is found that \( d=15 \) yields optimal results for this mapping under a certain constraint, determine the effective rank of the feature map's image space.
💡 Hint 1 of 3
The feature map is defined as \( \phi(\mathbf{x}) = [\mathbf{x}^T \mathbf{x}, \mathbf{x}^T \mathbf{x}, \dots, \mathbf{x}^T \mathbf{x}]^T \), where \( \mathbf{x} \in \mathbb{R}^{10} \).
💡 Hint 2 of 3
The term \( \mathbf{x}^T \mathbf{x} \) is the squared Euclidean norm of \( \mathbf{x} \), denoted as \( \|\mathbf{x}\|^2 \). This is a scalar value.
💡 Hint 3 of 3
The problem states that \(d\), but the effective rank of the image of this specific feature map is always 1, as all output vectors lie on a single line passing through the origin.
The feature map is defined as \( \phi(\mathbf{x}) = [\mathbf{x}^T \mathbf{x}, \mathbf{x}^T \mathbf{x}, \dots, \mathbf{x}^T \mathbf{x}]^T \), where \( \mathbf{x} \in \mathbb{R}^{10} \). The term \( \mathbf{x}^T \mathbf{x} \) is the squared Euclidean norm of \( \mathbf{x} \), denoted as \( \|\mathbf{x}\|^2 \). This is a scalar value. Thus, the mapping \( \phi \) produces a vector where each component is the same scalar value, \( \|\mathbf{x}\|^2 \). Let \( k = \|\mathbf{x}\|^2 \). Then \( \phi(\mathbf{x}) = [k, k, \dots, k]^T \) in \( \mathbb{R}^{d} \). This means that the image of the mapping \( \phi \) is a subspace spanned by a single vector. For example, if \( d=15 \), then \( \phi(\mathbf{x}) = [k, k, \dots, k]^T \) which can be written as \( k \cdot [1, 1, \dots, 1]^T \). The vector \( [1, 1, \dots, 1]^T \) forms a basis for the image space. Therefore, the dimension of the image space, which is equivalent to its rank, is 1, regardless of the value of \( d \) (as long as \( d \ge 1 \)). The problem states that \( d=15 \), but the effective rank of the image of this specific feature map is always 1, as all output vectors lie on a single line passing through the origin.
الاحتمال الشرطي وقاعدة بايز ومصنفات الذكاء الاصطناعي — مسألة مهيكلة من ٦ درجات
6 نقاط
الآلة الحاسبة مسموحة
في موضوع الاحتمال الشرطي وقاعدة بايز ومصنفات الذكاء الاصطناعي، ادرس الدالة \(f(x) = 5x^2 - 4x + 1\) على الفترة \([0, 3]\).
(a)2 نقطة
احسب قيمتي \(f(0)\) و \(f(2)\).
معيار التصحيح والإجابة النموذجية
[M1]يعوّض القيمتين في الدالة(1 نقطة)
[A1]يحصل على 1 و 13(1 نقطة)
(b)2 نقطة
أوجد المشتقة \(f'(x)\) والنقطة الحرجة \(x_c\).
معيار التصحيح والإجابة النموذجية
[M1]يشتق الدالة التربيعية(1 نقطة)
[A1]يحل لإيجاد النقطة الحرجة(1 نقطة)
(c)2 نقطة
احسب متوسط معدل التغيّر من \(x = 0\) إلى \(x = 2\).
معيار التصحيح والإجابة النموذجية
[M1]يطبّق قانون متوسط معدل التغيّر(1 نقطة)
[A1]يبسّط الناتج إلى 6(1 نقطة)
الحل الكامل التفصيلي
(أ) \(f(0)=1\) و \(f(2)=13\). (ب) \(f'(x)=10x-4\). (ج) متوسط معدل التغيّر يساوي \(6\).