AI engineering glossary · Classical ML algorithms
What is logistic regression?
Logistic regression: A supervised method for classification that computes a weighted sum of features and squeezes it through an S-shaped curve to give a probability between 0 and 1. A cut-off, often 0.5, turns that probability into a class label. Despite the name it predicts categories, and it is a strong, interpretable baseline.
Logistic regression: an example
An email with weighted score 2.2 gets probability 1 / (1 + e^-2.2) = 0.90 of being spam, so it is filtered.
Logistic regression in Python
A short example you can run (Python 3.11, NumPy, scikit-learn). The output below is what it really prints.
import numpy as np
from sklearn.linear_model import LogisticRegression
hours = np.array([[1], [2], [3], [4], [5], [6], [7], [8]])
passed = np.array([0, 0, 0, 1, 0, 1, 1, 1])
m = LogisticRegression().fit(hours, passed)
for h in (2, 4.5, 7):
print(f"{h} hours -> P(pass) = {m.predict_proba(np.array(h).reshape(1, 1))[0, 1]:.2f}")Output
2 hours -> P(pass) = 0.10 4.5 hours -> P(pass) = 0.50 7 hours -> P(pass) = 0.90
Related terms
More Classical ML algorithms terms
- Manhattan distance
- Matrix factorisation
- Maximum margin classifier
- Mini-batch k-means
- Multicollinearity
- Multinomial naive Bayes
- Multiple linear regression
- Naive Bayes
Where you learn it
Logistic regression is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.