A linear rule for categories.
Understand scores, probabilities, thresholds, and why logistic regression is a classifier.
Start with the meaning.
Despite its name, logistic regression is commonly used for classification. It starts with a weighted sum of features, much like linear regression, then transforms that score with a logistic function into a number between 0 and 1. That number can be interpreted as an estimated probability for one class when the model is suitable and calibrated. A threshold converts it into a yes-or-no label. The weighted sum determines a straight decision boundary in the original feature space unless we transform the features first.
For one feature, imagine predicting whether a measurement belongs to a high or low group. As the feature increases, the model's score may increase. The logistic transformation changes gradually from near 0 to near 1 rather than allowing impossible probabilities below 0 or above 1. The probability is still learned from data; it is not guaranteed to match the real frequency of outcomes without evaluation.
How the idea works.
The coefficients change the log-odds, a mathematical way to compare the chance of an event with the chance it does not occur. A positive coefficient pushes the class-1 probability upward when the feature increases, holding other model inputs fixed. The coefficient is not the direct change in probability, because the logistic curve is steeper near its middle and flatter near its ends. Intercept and feature scaling also influence how to read the value.
Logistic regression typically includes regularisation. This helps control large coefficients when the data offers several possible separating directions. Class weights can alter the fitting objective when classes have different importance, but changing weights does not magically fix missing data or make predicted probabilities calibrated. Thresholds and class weights solve related but different problems: one changes fitting emphasis; the other changes the final decision rule.
For more than two classes, common implementations use a multiclass extension. The output can include a probability for each class, and predict chooses one label. A model may be wrong even with its highest probability, and the probability values need checking against actual outcomes. Always separate the continuous score, probability estimate, and chosen label when discussing a classifier.
Follow the code.
from sklearn.linear_model import LogisticRegression
X = [[1], [2], [3], [6], [7], [8]]
y = [0, 0, 0, 1, 1, 1]
model = LogisticRegression()
model.fit(X, y)
print(model.predict([[5]]))
print(model.predict_proba([[5]]))The feature rows are numbers; the targets say whether each belongs to class 0 or class 1. The learner finds a smooth transition between the groups. predict([[5]]) returns the selected class for a new value 5. predict_proba([[5]]) returns one row containing the model's probability estimates in the order of model.classes_. The exact numeric probabilities depend on the fitted coefficients and regularisation, so the example does not promise a particular decimal value.
The classification boundary lies somewhere between the lower and higher groups. If a task's cost of a false positive differs from a false negative, the default label returned by predict may not be the best decision. The probability estimate allows a separate threshold policy, chosen using validation evidence. The six training examples alone cannot establish how well that policy will work elsewhere.
What the result does not say.
A linear decision boundary is a limitation when classes wrap around each other or depend on feature interactions. Transforming features or choosing a nonlinear family can help, but adds decisions that need validation.
Interpreting a coefficient as a causal effect is unsafe when variables are confounded or selection into the dataset is biased. A useful predictive signal and a useful intervention are different claims.
One clear idea.
Logistic regression turns a weighted score into class probabilities; a threshold turns probabilities into decisions.
The ML cookbook
Complete, explained Python workflows sit alongside this reading course.