04.05 Lesson 5 of 16

1 h

Logistic Regression & Probabilities

Turn a linear score into a class probability and understand how logistic regression separates two classes.

By the end of this lesson

You will be able to

  • Explain the sigmoid function and log-odds.
  • Distinguish a probability estimate from a thresholded class prediction.
  • Interpret coefficients and regularization.
  • Identify when a linear decision boundary may be too restrictive.

From a weighted score to a probability

Logistic regression first computes a linear score z = wᵀx + b, then maps it through the sigmoid function σ(z) = 1 / (1 + e⁻ᶻ). The result lies between zero and one and is interpreted as the model's estimated probability for the positive class. The logit, log(p / (1-p)), is linear in the features. It is still a linear model in its score; the sigmoid provides the probability mapping.

from sklearn.linear_model import LogisticRegression

classifier = Pipeline([
    ("prepare", preprocess),
    ("model", LogisticRegression(max_iter=1000)),
])
classifier.fit(X_train, y_train)
probabilities = classifier.predict_proba(X_valid)[:, 1]

A probability is not yet a decision

A predicted probability of 0.35 is not automatically a negative decision. A threshold converts probabilities into labels, and 0.5 is only a common default. A lower threshold may increase recall while reducing precision; a higher threshold often does the reverse. Coefficients describe conditional associations inside the model and depend on feature scaling, encoding, regularization and correlated inputs. They are not causal effects.

Apply what you learned

Exercise

Inspect logistic probabilities

Fit logistic regression to a binary dataset and inspect probabilities, coefficients and thresholded predictions.

  1. Use a preprocessing Pipeline for numeric and categorical fields.
  2. Fit logistic regression on training data only.
  3. Inspect validation probabilities and confirm they lie between zero and one.
  4. Compare predicted labels at thresholds 0.5 and 0.3.
  5. Explain why the threshold changes decisions without changing fitted coefficients.
Done when

The model returns probability estimates and the learner can distinguish the fitted probability function from a later decision threshold.

Free references

Study resources

2 links
  1. 01
    Logistic Regression Video

    Watch the individual logistic regression video. Focus on the sigmoid mapping and the distinction between score and probability.

  2. 02
    Linear Models Article

    Read Logistic Regression, including regularization and probability-related notes.

Check your understanding

Self-test

2 questions
  1. Question 1

    What does the sigmoid function do in logistic regression?

  2. Question 2

    Does changing the classification threshold retrain logistic regression?

Completion check

Move on when

You can fit a logistic regression pipeline, inspect probabilities and demonstrate how a threshold changes labels.

Quick find

Search Michi

Type to search every stage, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels