✓ تم التحقق من المنهج الرسميمعايير الجودة والصرامة ↗
7

الانحدار اللوجستي والحدود الفاصلة للتصنيف

🤖 AI Math Unit 7 — Logistic Classification Applied 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.

● Definition 7.1 — Sigmoid & Binary Cross-Entropy
1. Sigmoid Function: sigma(z) = \frac{1}{1 + e^{-z}}.
Key properties: sigma(0) = 0.5, \( \lim_{z \to \infty} \sigma(z) = 1 \), \( \lim_{z \to -\infty} \sigma(z) = 0 \). Derivative: \( \sigma'(z) = \sigma(z)(1 - \sigma(z)) \).

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] \]
● الفهم المفاهيمي العميق — الانحدار اللوجستي والحدود الفاصلة للتصنيف

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\)
تفاعلي
قرار 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\).

جدول مصفوفة الالتباس للتصنيف الثنائي \((TP, FP, FN, TN)\) لحساب الدقة والحساسية ومعيار \(F_1\).
Odds Ratio (الانحدار اللوجستي والحدود الفاصلة للتصنيف)
\( \text{Odds} = \frac{p}{1-p} = e^{\mathbf{w}^T\mathbf{x}} \)
Log-Odds (Logit) (الانحدار اللوجستي والحدود الفاصلة للتصنيف)
\( \ln\left(\frac{p}{1-p}\right) = \mathbf{w}^T\mathbf{x} \)
Decision Boundary (الانحدار اللوجستي والحدود الفاصلة للتصنيف)
\( \hat{y} \ge 0.5 \iff \mathbf{w}^T\mathbf{x} \ge 0 \) (hyperplane separating classes)
Loss المشتقة
\(\frac{\partial L}{\partial \mathbf{w}} = (\hat{y} - y)\mathbf{x}\) (remarkably clean!) (الانحدار اللوجستي والحدود الفاصلة للتصنيف)
◆ لماذا تعمل هذه القاعدة — الاشتقاق الرياضي (الانحدار اللوجستي والحدود الفاصلة للتصنيف)

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 \).
▸ عرض خطوات الحل بالتفصيل


(a) Compute logit \( z \):
\( z = 0.8(4.5) - 2.4 = 3.6 - 2.4 = 1.2 \).
Compute probability via Sigmoid:
\[ \hat{y} = \sigma(1.2) = \frac{1}{1 + e^{-1.2}} = \frac{1}{1 + 0.3012} = \frac{1}{1.3012} \approx 0.7685 \] (76.85% probability).

(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.

تشخيص الأخطاء — مقارنة الخطأ الشائع بالطريقة الصحيحة (الانحدار اللوجستي والحدود الفاصلة للتصنيف)
الخطأ الشائع للطالبالسبب الرياضي للخطأالطريقة الصحيحة المعتمدة
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 integralEvaluates 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|\)يؤدي إلى فقدان جذور صحيحة أو إدخال جذور دخيلة لا تحقق المعادلة الأصلية.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)) \).
💡 Hint 2 of 3
Substituting \( \sigma(z_0) = 0.40 \): \(\sigma'(z_0) = (0.40)(1 - 0.40)\). Substitute and simplify: \(\sigma'(z_0) = (0.40)(0.60)\).
💡 Hint 3 of 3
Compute the final value from: \((0.40)(0.60)\).
The derivative of sigmoid satisfies \( \sigma'(z) = \sigma(z)(1 - \sigma(z)) \). Substituting \( \sigma(z_0) = 0.40 \): \( \sigma'(z_0) = (0.40)(1 - 0.40) = (0.40)(0.60) = 0.2400 \).
[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:

FamilyTransformed Form \(g(x)\)DomainRange (\(a > 0\))Key Geometric Feature
Constant\(f(x) = c\)\((-\infty, \infty)\)\(\{c\}\)Horizontal line, slope \(0\)
Linear\(a(x - h) + k\)\((-\infty, \infty)\)\((-\infty, \infty)\)Constant slope \(m = a\), pivot \((h, k)\)
Quadratic\(a(x - h)^2 + k\)\((-\infty, \infty)\)\([k, \infty)\)Parabola vertex \((h, k)\), axis \(x = h\)
Cubic\(a(x - h)^3 + k\)\((-\infty, \infty)\)\((-\infty, \infty)\)Inflection center \((h, k)\), S-curve
Absolute Value\(a|x - h| + k\)\((-\infty, \infty)\)\([k, \infty)\)V-corner vertex \((h, k)\), slopes \(\pm a\)
Radical\(a\sqrt{x - h} + k\)\([h, \infty)\)\([k, \infty)\)Endpoint \((h, k)\), half-parabola
Rational\(\dfrac{a}{x - h} + k\)\(x \neq h\)\(y \neq k\)Vertical asymptote \(x = h\), horizontal \(y = k\)
Exponential\(a \cdot 2^{x - h} + k\)\((-\infty, \infty)\)\((k, \infty)\)Horizontal asymptote \(y = k\), anchor \((h, a+k)\)
Logarithmic\(a\ln(x - h) + k\)\((h, \infty)\)\((-\infty, \infty)\)Vertical asymptote \(x = h\), anchor \((h+1, k)\)
⊙ مستكشف تفاعلي · مختبر النمو والاضمحلال الأسي وتحويلات الدوال الأم
تفاعلي
المعادلة النشطةf(x) = 2ˣ
المجال(−∞, ∞)
المدى(0, ∞)
الرأس / خطوط التقاربHA: y = 0 · Anchor (0, 1)
نقاط التقاطع مع المحورينy-int: (0, 1) · x-int: none

يبدأ على الدالة الأسية \(f(x) = a\cdot 2^{x - h} + k\) بخط تقارب أفقي \(y = k\) ونقطة مرجعية \((h, a + k)\). اسحب \((h, k)\) أو انتقل إلى الدالة اللوغاريتمية العكسية.

الانحدار اللوجستي والحدود الفاصلة للتصنيف — مسألة مهيكلة من ٦ درجات

6 نقاط بدون آلة حاسبة
في موضوع الانحدار اللوجستي والحدود الفاصلة للتصنيف، ادرس الدالة \(f(x) = 4x^2 - 4x + 1\) على الفترة \([0, 3]\).
  1. (a)2 نقطة
    احسب قيمتي \(f(0)\) و \(f(2)\).
    معيار التصحيح والإجابة النموذجية
    • [M1] يعوّض القيمتين في الدالة (1 نقطة)
    • [A1] يحصل على 1 و 9 (1 نقطة)
  2. (b)2 نقطة
    أوجد المشتقة \(f'(x)\) والنقطة الحرجة \(x_c\).
    معيار التصحيح والإجابة النموذجية
    • [M1] يشتق الدالة التربيعية (1 نقطة)
    • [A1] يحل لإيجاد النقطة الحرجة (1 نقطة)
  3. (c)2 نقطة
    احسب متوسط معدل التغيّر من \(x = 0\) إلى \(x = 2\).
    معيار التصحيح والإجابة النموذجية
    • [M1] يطبّق قانون متوسط معدل التغيّر (1 نقطة)
    • [A1] يبسّط الناتج إلى 4 (1 نقطة)
الحل الكامل التفصيلي
(أ) \(f(0)=1\) و \(f(2)=9\). (ب) \(f'(x)=8x-4\). (ج) متوسط معدل التغيّر يساوي \(4\).
📝 اختبار الفصل