🤖 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.
2. Binary Cross-Entropy Loss: For true label \( y \in \{0, 1\} \) and model prediction \( \hat{y} = \sigma(\mathbf{w}^T\mathbf{x}) \): \[ L(y, \hat{y}) = -\Big[ y \ln\hat{y} + (1 - y) \ln(1 - \hat{y}) \Big] \]
● Deep Conceptual Intuition — Logistic Regression & Classification Boundaries
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.
Logistic sigmoid curve \(\sigma(z) = \dfrac{1}{1 + e^{-z}}\) mapping real logits to probabilities in \((0, 1)\) with decision threshold \(0.5\).
Live numerical table for Logistic Regression Sigmoid \(\sigma\)(wx + \(b\)) & Decision Boundary
Parameter / Metric
Value
Decision Boundary x* = \(-b / w\)\(x* = 0.50\)
Probability \(\sigma (w \cdot 1 + b)\)\(\sigma (z) = 0.711\)
Binary Cross-Entropy LossBCE ≈ 0.389
Class 0 (indigo dots at \(y = 0\)) and Class 1 (amber dots at \(y = 1\)) are separated by the sigmoid curve \(P(y=1|x) = 1\)/(1 + e^(−(wx+\(b\)))), which crosses 0.5 at x* = \(-b / w\).
Binary Classification Contingency Table — illustrating key geometric and analytical relationships in Logistic Regression & Classification Boundaries.
◆ Why It Works — First-Principles Derivation (Logistic Regression & Classification Boundaries)
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
Problem. 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)
Problem. 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.
▸ Show step-by-step solution
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)
Problem. 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?
▸ Show step-by-step solution
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)
Problem. 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?
▸ Show step-by-step solution
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.
⚠️ Common Exam Traps — Logistic Regression & Classification Boundaries
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.
Error Diagnosis — Common Student Traps vs. Exam-Board Method (Logistic Regression & Classification Boundaries)
Common Student Trap
Why It Fails Mathematically
Correct Exam-Board Method
Writing \(\ln|y| = x^2 + C \implies y = e^{x^2} + C\)
Exponentiation distributes over addition as multiplication (\(e^{a+b} = e^a e^b\)), not addition.
Write \(y = e^{x^2 + C} = Ae^{x^2}\) and solve for \(A\) using the initial condition.
Leaving original \(x\)-limits on a \(u\)-substituted definite integral
Evaluates the antiderivative \(F(u)\) at \(x\)-values instead of \(u(x)\)-values.
Convert bounds immediately: \(u_{\text{low}} = u(a)\) and \(u_{\text{high}} = u(b)\).
Computing total distance as \(\left|\int_{t_1}^{t_2} v(t)\,dt\right|\)
Cancels forward and backward motion (net displacement) instead of accumulating total path length.
Split the integral at every root where \(v(t) = 0\) and integrate \(|v(t)|\).
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:
⊙ Explorer · Exponential Growth/Decay & Parent Functions Lab
interactive
Comparison of parent function \(f(x)\) and transformed function \(g(x) = a\,f(x - h) + k\) across integer inputs.
\(x\)
Parent \(f(x)\)
Transformed \(g(x)\)
Active Equationf(x) = 2ˣ
Domain(−∞, ∞)
Range(0, ∞)
Vertex / AsymptotesHA: y = 0 · Anchor (0, 1)
Interceptsy-int: (0, 1) · x-int: none
Starts on the exponential family \(f(x) = a\cdot 2^{x - h} + k\) with horizontal asymptote \(y = k\) and anchor \((h, a + k)\). Drag \((h, k)\) or switch to its logarithmic inverse.
Logistic Regression & Classification Boundaries — 6-Mark Structured Problem
6 pts
No Calculator
For Logistic Regression & Classification Boundaries, examine the quadratic-rate model \(f(x) = 4x^2 - 4x + 1\) on \(x \in [0, 3]\).
(a)2 pts
Compute \(f(0)\) and \(f(2)\).
Scoring Guideline & Justification
[M1]Substitutes x=0 and x=2(1 pt)
[A1]Obtains 1 and 9(1 pt)
(b)2 pts
Find the derivative/rate \(f'(x)\) and critical point \(x_c\).
Scoring Guideline & Justification
[M1]Differentiates to 8x - 4(1 pt)
[A1]Solves x_c = 4/8(1 pt)
(c)2 pts
Calculate the average rate of change from \(x = 0\) to \(x = 2\).