🤖 AI Math Unit 7 — Logistic ClassificationApplied STEM · Binary classification & probabilities · The Sigmoid function σ(z) = 1 / (1 + e⁻ᶻ) · Log-odds (Logit) transformation · Binary Cross-Entropy (Log Loss) function · Linear decision boundaries and threshold tuning
When the target variable is categorical (0 or 1, positive or negative), standard linear regression fails. Logistic regression maps continuous linear combinations to calibrated probabilities using the Sigmoid curve.
Accumulation, Antiderivatives & Differential Flows: By the Fundamental Theorem of Calculus, the accumulation function \(A(x) = \int_a^x f(t)\,dt\) satisfies \(A'(x) = f(x)\), linking instantaneous rates of change to net signed area. In first-order differential equations \(\dfrac{dy}{dx} = g(x)h(y)\), separation of variables \(\int \dfrac{1}{h(y)}\,dy = \int g(x)\,dx + C\) reconstructs the family of integral curves across the slope field.
منحنى السيجمويد اللوجستي \(\sigma(z) = \dfrac{1}{1 + e^{-z}}\) الذي يحوّل اللوجيت الحقيقي إلى احتمال مقيد في \((0, 1)\) مع عتبة القرار \(0.5\).
⊙ مستكشف تفاعلي · الانحدار اللوجستي ودالة السيجمويد σ(wx + b) وحد القرار \(\sigma\) ، \(b\)
تفاعلي
جدول عددي حي لـ Logistic Regression Sigmoid \(\sigma\)(wx + \(b\)) & قرار Boundary
المتغير / المعيار
القيمة
قرار Boundary x* = \(-b / w\)\(x* = 0.50\)
احتمال \(\sigma (w \cdot 1 + b)\)\(\sigma (z) = 0.711\)
Binary تبادلي-Entropy LossBCE ≈ 0.389
فصل 0 (نيلي dots عند \(y = 0\)) و فصل 1 (كهرماني dots عند \(y = 1\)) تكون separated بواسطة sigmoid منحنى \(P(y=1|x) = 1\)/(1 + e^(−(wx+\(b\))))، التي crosses 0.5 عند x* = \(-b / w\).
◆ لماذا تعمل هذه القاعدة — الاشتقاق الرياضي (الانحدار اللوجستي والحدود الفاصلة للتصنيف)
Why Integration by Parts & Integrating Factors Work: Differentiating a product \(u(x)v(x)\) gives \((uv)' = u'v + uv'\). Integrating both sides and rearranging yields the Integration by Parts formula:
\[ \int u\,\frac{dv}{dx}\,dx = u v - \int v\,\frac{du}{dx}\,dx \]
Similarly, for a linear first-order ODE \(y' + P(x)y = Q(x)\), multiplying by the integrating factor \(\mu(x) = e^{\int P(x)\,dx}\) (which satisfies \(\mu'(x) = P(x)\mu(x)\)) collapses the left-hand side into an exact product derivative: \(\dfrac{d}{dx}\bigl[\mu(x)y\bigr] = \mu(x)Q(x)\).
Worked Example 7.A — Probability & Cross-Entropy Calculation
المسألة. A medical AI model has learned weights \( w = 0.8 \) and bias \( b = -2.4 \) for predicting whether a tumor is malignant (\( y=1 \)) based on diameter \( x \) in cm: \[ z = 0.8x - 2.4, \quad \hat{y} = \sigma(z) \] (a) Find the predicted malignancy probability for a tumor of diameter \( x = 4.5 \text{ cm} \). (b) If the actual diagnosis was malignant (\( y = 1 \)), calculate the binary cross-entropy loss \( L \).
(b) Binary cross-entropy with \( y = 1 \): \[ L = -\Big[ 1 \cdot \ln(0.7685) + 0 \cdot \ln(1 - 0.7685) \Big] = -\ln(0.7685) \approx -(-0.2633) = 0.2633 \]. Answer: (a) \( \hat{y} \approx 0.769 \) (76.9%), (b) Loss \( L \approx 0.263 \).
Worked Example \(B\) — Logistic Regression & Classification Boundaries (Hard Application)
المسألة. Consider a binary classification problem where the decision boundary is defined by the logistic function \( p(x) = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x_1 + \beta_2 x_2)}} \), which represents the probability of a data point \( \mathbf{x} = (x_1, x_2) \) belonging to class 1. The estimated model parameters are \( \beta_0 = -3 \), \( \beta_1 = 1 \), and \( \beta_2 = -2 \). We are interested in the geometric shape of the classification boundary. The classification boundary occurs where \( p(x) = 0.5 \). Find the equation of this boundary in the \( x_1x_2 \)-plane.
▸ عرض خطوات الحل بالتفصيل
The logistic regression model gives the probability of belonging to class 1 as \( p(x) = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x_1 + \beta_2 x_2)}} \). The classification boundary is the set of points where \( p(x) = 0.5 \).
Setting \( p(x) = 0.5 \), we have:
\( 0.5 = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x_1 + \beta_2 x_2)}} \)
This implies:
\( 1 + e^{-(\beta_0 + \beta_1 x_1 + \beta_2 x_2)} = 2 \)
Therefore:
\( e^{-(\beta_0 + \beta_1 x_1 + \beta_2 x_2)} = 1 \)
Taking the natural logarithm of both sides:
\( -(\beta_0 + \beta_1 x_1 + \beta_2 x_2) = \ln(1) \)
Since \( \ln(1) = 0 \), we get:
\( \beta_0 + \beta_1 x_1 + \beta_2 x_2 = 0 \)
This is the equation of the linear decision boundary.
Substitute the given parameter values: \( \beta_0 = -3 \), \( \beta_1 = 1 \), and \( \beta_2 = -2 \).
\( -3 + x_1 + (-2) \cdot x_2 = 0 \)
\( -3 + x_1 - 2x_2 = 0 \)
We need to express this in the form \( x_2 = f(x_1) \).
\( 2x_2 = x_1 - 3 \)
\( x_2 = \frac{1}{2} x_1 - \frac{3}{2} \)
This matches choice A.
Worked Example \(C\) — Logistic Regression & Classification Boundaries (Easy Application)
المسألة. Consider a simple logistic regression model where the decision boundary is defined by the linear equation \(w_1x_1 + w_2x_2 + b = 0\). If the weights are \(w_1 = 2\) and \(w_2 = 3\), and the bias is \(b = -7\), what is the equation of the decision boundary?
▸ عرض خطوات الحل بالتفصيل
The decision boundary in a logistic regression model is defined by the equation where the log-odds are zero. This corresponds to a linear combination of the input features and weights, plus the bias, being equal to zero. Given the weights \(w_1 = 2\) and \(w_2 = 3\), and the bias \(b = -7\), the equation of the decision boundary is \(w_1x_1 + w_2x_2 + b = 0\). Substituting the given values, we get \(2x_1 + 3x_2 + (-7) = 0\), which simplifies to \(2x_1 + 3x_2 - 7 = 0\).
Worked Example \(D\) — Logistic Regression & Classification Boundaries (Medium Application)
المسألة. Consider a simple logistic regression model where the decision boundary is defined by the equation \( -1.5x_1 + 2x_2 + 5 = 0 \). For a data point \( (x_1, x_2) \), if \( -1.5x_1 + 2x_2 + 5 < 0 \), it is classified into Class 0. Otherwise, it is classified into Class 1. Which of the following points lies on the decision boundary?
▸ عرض خطوات الحل بالتفصيل
The decision boundary is defined by the equation \( -1.5x_1 + 2x_2 + 5 = 0 \). To find which point lies on the boundary, we substitute the coordinates of each point into the equation. For point \( (-1, 1) \): \( -1.5(-1) + 2(1) + 5 = 1.5 + 2 + 5 = 8.5 \), which is not 0. For point \( (2, -2) \): \( -1.5(2) + 2(-2) + 5 = -3 - 4 + 5 = -2 \), which is not 0. For point \( (0, -2.5) \): \( -1.5(0) + 2(-2.5) + 5 = 0 - 5 + 5 = 0 \). This point lies on the boundary. For point \( (3, 0.5) \): \( -1.5(3) + 2(0.5) + 5 = -4.5 + 1 + 5 = 1.5 \), which is not 0. Therefore, the point \( (0, -2.5) \) lies on the decision boundary.
1. Adding \(+C\) Only After Exponentiating in Separable ODEs: In \(\dfrac{dy}{dx} = 3xy\), integrating gives \(\ln|y| = \tfrac{3}{2}x^2 + C \implies y = Ae^{3x^2/2}\) where \(A = \pm e^C\). Writing \(y = e^{3x^2/2} + C\) is a fatal algebraic error that forfeits all follow-up marks on Mathematics for Artificial Intelligence & Machine Learning.
2. Forgetting to Transform Limits in \(u\)-Substitution: In definite integrals \(\int_a^b f(g(x))g'(x)\,dx\), you must replace the limits \(x = a, b\) with \(u = g(a), g(b)\) immediately.
Quick Verification Trick (Mathematics for Artificial Intelligence & Machine Learning): For any indefinite integral \(\int f(x)\,dx = F(x) + C\), differentiate your answer \(F'(x)\) mentally—especially the coefficient \(1/k\) from chain-rule reversal \(\int e^{kx}\,dx = \tfrac{1}{k}e^{kx} + C\)—before moving on.
[Practice 1 · Hard] The sigmoid activation function is \( \sigma(z) = \frac{1}{1 + e^{-z}} \). If \( \sigma(z_0) = 0.40 \), what is the value of the derivative \( \sigma'(z_0) \)?
💡 Hint 1 of 3
The derivative of sigmoid satisfies \( \sigma'(z) = \sigma(z)(1 - \sigma(z)) \).
[Practice 2 · Easy] A fitted simple linear regression model is \( \hat{y} = 7x + 18 \). What is the predicted target value \( \hat{y} \) when the input feature is \( x = 4 \)?
💡 Hint 1 of 3
Substitute \( x = 4 \) into the regression equation: \(\hat{y} = 7(4) + 18\).
💡 Hint 2 of 3
Substitute and simplify: \(\hat{y} = 28 + 18\).
💡 Hint 3 of 3
Compute the final value from: \(28 + 18\).
Substitute \( x = 4 \) into the regression equation: \( \hat{y} = 7(4) + 18 = 28 + 18 = 46 \).
[Practice 3 · Medium] A binary classification model uses a logistic sigmoid function \( \sigma(z) = \frac{1}{1 + e^{-z}} \). The decision boundary is defined by \( \sigma(z) = 0.5 \), where \( z = w_1 x_1 + w_0 \). For a dataset with two features \( x_1 \) and \( x_2 \), the model's linear component is \( z = 2x_1 - x_2 + b \). If the classification boundary passes through the point \( (x_1, x_2) = (3, 1) \), what is the value of the bias \( b \)?
💡 Hint 1 of 3
The logistic sigmoid function is \( \sigma(z) = \frac{1}{1 + e^{-z}} \). The decision boundary is where \( \sigma(z) = 0.5 \). Setting \( \sigma(z) = 0.5 \) gives \( \frac{1}{1 + e^{-z}} = 0.5 \), which implies \( 1 = 0.5(1 + e^{-z}) \), so \( 2 = 1 + e^{-z} \), and \( e^{-z} = 1 \). This occurs when \( -z = 0 \), or \( z = 0 \). Therefore, the decision boundary is defined by \( z = 0 \).
💡 Hint 2 of 3
The linear component of the model is given by \( z = w_1 x_1 + w_2 x_2 + b \). In this problem, \( z = 2x_1 - x_2 + b \). Since the decision boundary is \( z = 0 \), we have \( 2x_1 - x_2 + b = 0 \).
💡 Hint 3 of 3
Use the resulting form to finish: \(5 + b\).
The logistic sigmoid function is \( \sigma(z) = \frac{1}{1 + e^{-z}} \). The decision boundary is where \( \sigma(z) = 0.5 \). Setting \( \sigma(z) = 0.5 \) gives \( \frac{1}{1 + e^{-z}} = 0.5 \), which implies \( 1 = 0.5(1 + e^{-z}) \), so \( 2 = 1 + e^{-z} \), and \( e^{-z} = 1 \). This occurs when \( -z = 0 \), or \( z = 0 \). Therefore, the decision boundary is defined by \( z = 0 \).
The linear component of the model is given by \( z = w_1 x_1 + w_2 x_2 + b \). In this problem, \( z = 2x_1 - x_2 + b \).
Since the decision boundary is \( z = 0 \), we have \( 2x_1 - x_2 + b = 0 \).
The classification boundary passes through the point \( (x_1, x_2) = (3, 1) \). Substituting these values into the equation for the decision boundary:
\( 2(3) - 1 + b = 0 \)
\( 6 - 1 + b = 0 \)
\( 5 + b = 0 \)
\( b = -5 \)
[Practice 4 · Hard] For a bivariate feature dataset, \( \text{Cov}(x, y) = 24 \), \( \text{Var}(x) = 8 \), \( \bar{x} = 5 \), and \( \bar{y} = 30 \). Compute the OLS regression slope \( \hat{\beta}_1 \) and intercept \( \hat{\beta}_0 \).
💡 Hint 1 of 3
The OLS slope is \(\hat{\beta}_1 = \frac{\text{Cov}(x, y)}{\text{Var}(x)} = \frac{24}{8}\).
💡 Hint 2 of 3
The intercept is: \(\hat{\beta}_0 = \bar{y} - \hat{\beta}_1\bar{x}\). Substitute and simplify: \(\hat{\beta}_0 = 30 - (3)(5)\).
💡 Hint 3 of 3
Compute the final value from: \(30 - 15\).
The OLS slope is \( \hat{\beta}_1 = \frac{\text{Cov}(x, y)}{\text{Var}(x)} = \frac{24}{8} = 3 \). The intercept is \( \hat{\beta}_0 = \bar{y} - \hat{\beta}_1\bar{x} = 30 - (3)(5) = 30 - 15 = 15 \).
[Practice 5 · Easy] In evaluating a binary classifier, the confusion matrix shows \( TP = 45 \), \( TN = 40 \), \( FP = 10 \), and \( FN = 10 \). Compute the overall classification accuracy.
💡 Hint 1 of 3
Accuracy is the ratio of correct predictions to total samples: \(\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}\).
💡 Hint 2 of 3
Substitute and simplify: \(\text{Accuracy} = \frac{45 + 40}{105}\).
💡 Hint 3 of 3
Compute the final value from: \(\frac{45 + 40}{105}\).
Accuracy is the ratio of correct predictions to total samples: \( \text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN} = \frac{45 + 40}{105} = \frac{85}{105} = 81.0\% \).
● Master Atlas of the 9 Main Parent Functions & Universal Transformation Law
Every algebraic and elementary transcendental model is built by transforming one of the nine core parent functions via \(g(x) = a\,f(x - h) + k\), where \(|a|\) scales vertically (reflecting across the \(x\)-axis if \(a < 0\)), \(h\) shifts horizontally, and \(k\) shifts vertically: