Logistic Regression#
A linear model mapping features to a probability via the logistic function.
Important
✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.
What it is#
Logistic regression is a linear model for binary classification that predicts the probability of the positive class. Despite regression in the name it classifies: it outputs a probability, then a threshold (usually 0.5) assigns the label.
The sigmoid and log-odds#
It passes a linear combination through the sigmoid, squashing any real number into \((0, 1)\):
Equivalently, the log-odds (logit) — the natural log of the odds \(p/(1-p)\) — is linear in the features, which is what makes the coefficients interpretable:
Fitting by maximum likelihood#
Coefficients are chosen to maximize the likelihood of the observed labels — equivalently, to minimize the log loss (negative log-likelihood), a convex objective solved by gradient-based methods:
Assumptions and multiclass#
It assumes a linear log-odds relationship, few extreme outliers, and enough data; it extends to several classes via one-vs-rest or multinomial (softmax). Simple, fast and interpretable, it is a workhorse for spam, fraud and medical diagnosis.
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(max_iter=1000)
clf.fit(X_train, y_train)
proba = clf.predict_proba(X_test)[:, 1] # P(class 1)
Theme: AI & ML Concepts · All terminology
Hint
Mind map — connected ideas
Linear Models · Support Vector Machines (SVMs) · Neural Networks · Decision Trees · Multiclass AUROC · Discriminatory Power
Hint
More in AI & ML Concepts
AI (Artificial Intelligence) · Classification Models · Computer Vision (CV) · Decision Trees · Linear Models · LLMs (Large Language Models) · Machine Learning (ML) · Medical AI · Natural Language Processing (NLP) · Neural Networks · Regression Models · Support Vector Machines (SVMs) · Target Variable
See also
Source article Adapted (context, re-expressed) in our own words from: Logistic Regression (insightful-data-lab.com).