Class probabilities and Bayes classification
Choose the most likely label when all mistakes count equally. For input , the conditional class probability is
is the input, the label, a possible label, and means “given.” For classes, their probabilities sum to 1. With two labels, 0 and 1, .
The Bayes optimal classifier uses the true probabilities:
“Arg max” returns the label with the largest probability. With two labels, choose 1 when and 0 otherwise; either label is equally good at a tie, which we assign to 1.
Invented example: if , predicting 1 has error probability ; predicting 0 has error probability 0.8. The Bayes rule chooses 1. With estimated probabilities, the same decision rule gives an estimated classifier, not necessarily the true optimum.
Local averaging
Estimate a probability by counting nearby labels. For binary training labels , choose a neighborhood containing observations near input :
The index selects a training row, is the number of selected rows, and a hat marks an estimate. Since labels are 0 or 1, the sum counts class-1 observations. Choose class 1 when .
Invented neighborhood: gives and , so predict 1.
In many dimensions, small neighborhoods can be nearly empty and large ones can include dissimilar inputs: the curse of dimensionality.
Horizontal shifts
Work with the expression inside the function. If for and 0 otherwise, then
are the original interval endpoints; is the amount added to the input. For , shifts left by ; shifts right by . The height is unchanged. Included endpoints stay included.
Shared Q1: , , . Thus on and 0 outside. At , the inside is , so the value is 1.
Sigmoid identities
The sigmoid turns a real score into a probability between 0 and 1. For real number :
names the sigmoid; is the exponential base. Multiply numerator and denominator of the first form by to get the second, using .
Reverse the score to get the complementary probability:
For subtraction, put 1 over the denominator ; the numerator becomes .
Shared Q2 uses instead of ; the identities are identical. Check: , , and .
Logistic prediction
Add contributions, then apply the sigmoid. With features and fitted coefficients:
is feature of input , its fitted weight, the fitted intercept, and the score. Hats mean estimated from data. estimates the chance of class ; .
Shared Q5: supplied coefficients are ; supplied inputs are 40 study hours and GPA 3.5.
Estimated chance of an A: 37.8%. The probability is for this student; the training sample size is not an extra divisor.
Odds and logit
Odds compare the chance of class 1 with the chance of class 0. For probability , with :
is the natural logarithm. Logistic regression makes the log-odds a weighted score:
counts features, is feature , its coefficient, and the intercept. Equivalently,
Shared Q6 proof: exponentiate to get . Multiply by to get . Collect terms: . Divide by to obtain . In reverse, , so and its log is .
Coefficient meaning: holding other features fixed, increasing by 1 adds to log-odds and multiplies odds by . The probability change is not constant.
Numerical check: gives odds , log-odds , and the inverse gives .
Solving for a target probability
Turn the target chance back into a score, then solve a linear equation. Suppose one input can change while all others stay fixed:
is the intercept plus all fixed contributions, is the coefficient of , and is the predicted class-1 probability. For target probability :
is the requested probability, and is the natural logarithm. At , , so .
Shared Q5: keep GPA at 3.5. The fixed contribution is ; the hours coefficient is . For :
Check: , so . If , changing cannot change the model’s probability.
Probability thresholds
A probability becomes a label only after choosing a cutoff. Let , with logistic score and sigmoid relation . For threshold :
is the predicted label; is the minimum chance required to predict 1. Because the sigmoid increases with its score:
At , predict 1 exactly when . At equality, this convention assigns the tie to 1.
Invented example: predicts 1 at threshold 0.5 but predicts 0 at threshold 0.7. Changing the threshold changes the label, not the probability estimate.
Maximum likelihood
Fit coefficients that assign high probabilities to the observed labels. For independent training rows , let be the actual label and the proposed class-1 probability under coefficient vector .
For each row, use if , or if . Multiply the factors:
counts rows; means multiply. The exponent 0 makes the unused factor equal 1. Maximum likelihood estimation chooses
The hat marks fitted coefficients; “arg max” returns the coefficients giving the largest likelihood. Inputs and observed labels stay fixed while the candidate coefficients change.
Invented example: actual labels and proposed class-1 probabilities give
The middle row actually has label 0, so its factor is .
Logistic coefficient tests
Compare the fitted effect with its uncertainty. To test coefficient :
is the unknown population coefficient, its fitted estimate, and its estimated sample-to-sample variation. The test statistic is the estimate’s distance from zero in standard errors. This is distinct from the weighted score used to predict probabilities.
Under and suitable large-sample conditions, is approximately standard normal. The module uses the approximate two-sided rule:
Otherwise fail to reject, including at exactly . Failure to reject does not prove zero; rejection does not prove causation.
Invented fit: , . Then , so reject zero. In a multiple-input model, this tests the coefficient while the other modeled inputs are held fixed.
Multiclass logistic regression
One weighted score per class; divide each exponential by their total. For classes and input features:
selects a class, selects a feature, is that class’s intercept, and is its coefficient for feature . The index includes every class in the denominator; is the class- probability. is the exponential base. This conversion is called softmax.
Probabilities sum to 1. Predict the class with the largest , equivalently the largest score . Fit coefficients by maximizing the product of probabilities assigned to actual training labels.
Invented scores: give weights and total 6. Probabilities are ; predict class 3.
Denominator check: with all classes in the sum, do not add another 1. In reference-class notation, one class has score 0 and weight ; its denominator can be written as 1 plus the exponentials for the other classes.