Skip to content
intermediate

Generalized Linear Models Explained: Extend Linear Thinking Beyond Straight Lines

Linear regression draws a straight line through continuous numbers. Logistic regression draws an S-curve that outputs probabilities. They look like…

Published 2026-09-08Updated 2026-09-128 min read
Vibrant colored dye powders in sacks at a market, showcasing traditional craftsmanship.
Vibrant colored dye powders in sacks at a market, showcasing traditional craftsmanship. Photo by Francesco Sgura on Pexels.

Linear regression draws a straight line through continuous numbers. Logistic regression draws an S-curve that outputs probabilities. They look like completely different tools—different math, different loss functions, different mental pictures. So you file them away as separate recipes and move on.

Here is the reframe that saves you from that fragmented mental model: they are the same engine wearing different output layers. The engine is a weighted sum of your features. What changes is what you do with that sum before it becomes a prediction. Generalized linear models explained in one sentence: keep the linear core, swap the output machinery to match the kind of outcome you are predicting.

Why Linear Regression and Logistic Regression Feel Like Different Tools

The surface difference is real. Linear regression predicts a continuous value directly—house prices, temperatures, test scores. Logistic regression predicts a probability that must stay between 0 and 1—will this customer churn, does this email look like spam, is this tumor malignant?

But look under the hood and you will find the same engine running in both cases: a weighted sum of features. In linear regression, you compute that sum and call it the prediction. In logistic regression, you compute that sum and then push it through a transformation that squeezes it into the 0-to-1 range before calling it a probability.

The GLM framing makes this explicit. The weighted sum is the engine. The difference between models is what happens to that sum before it becomes a prediction. Once you see that, logistic regression stops being a separate algorithm and becomes a special case of a broader family—one that also includes models for count data, rates, and other outcome types you cannot reasonably fit with a straight line.

The Three Pieces of Every Generalized Linear Model

Every generalized linear model has three structural pieces. Once you name them, the whole family stops being a grab bag of unrelated techniques.

Piece one: the linear predictor. This is the familiar weighted sum from linear regression. Each feature gets a coefficient, you multiply and add, and out comes a single score. Nothing new here—you already know this equation.

Piece two: the link function. This is the bridge that maps the linear predictor onto the scale where your outcome actually lives. The link function is what lets one linear engine handle very different kinds of targets.

Piece three: the response distribution. This is your assumption about what kind of outcome you are modeling—continuous, binary, count—and how the noise around your predictions behaves.

Think of it this way: the linear predictor is the engine, the link function is the transmission, and the response distribution is the road surface the model must drive on. The engine stays the same. The transmission adapts its power to the terrain. And the road surface determines what kind of driving is even possible.

Knowledge check

Check your understanding

Answer this question before you continue.

Which set correctly names the three structural pieces of every generalized linear model?
Single Choice

Focus: Identify the three structural pieces that define a generalized linear model.

A three-column comparison shows linear, logistic, and Poisson regression sharing a weighted-sum linear predictor, then differing in link, response distribution, and output: continuous values, probabilities from 0 to 1, and nonnegative counts.
GLMs keep the same linear engine but adapt the link and response distribution to the outcome's constraints.

The link function is where the real magic happens, so let us look at three common ones.

The identity link does nothing. The linear predictor passes straight through to become the prediction. This recovers ordinary linear regression for continuous outcomes. If your outcome is roughly symmetric, unbounded, and continuous, you do not need a bridge at all.

The logit link is what logistic regression uses. It takes a linear score that could be any real number—negative, positive, huge—and maps it into a probability between 0 and 1. That S-curve you have seen is not a sign that the model went nonlinear. The model is still linear in its parameters. The link function is simply bending the output to respect the fact that probabilities cannot go below 0 or above 1.

The log link keeps predictions positive, which makes it the natural choice for count data. Number of purchases, number of clicks, number of insurance claims—these cannot go below zero, and a linear predictor that outputs −3 is meaningless for them. The log link ensures the model only produces non-negative predictions.

Here is the key insight: the link function is chosen to match the outcome's natural constraints, not for cosmetic reasons. This is also where beginners get confused. They see the S-curve of logistic regression and assume the model is nonlinear. It is not. The model is still linear in its parameters—the coefficients still add up in a straight line. Only the link bends the output.

Common mistake: Calling a GLM "nonlinear" because the output curve bends. The model is linear in its parameters. The link function is what bends the output to respect the outcome's constraints.

Knowledge check

Check your understanding

Answer this question before you continue.

A logistic regression prediction follows an S-curve. What does that imply about the model?
Misconception Check

Focus: Distinguish nonlinearity in a GLM's output from nonlinearity in its parameters.

Response Distributions: Matching the Model to the Data's Shape

The response distribution is the third piece, and it matters more than most introductions let on. It is not a formality. It changes how the model treats errors and what predictions it considers plausible.

Ordinary least squares assumes a normal (Gaussian) distribution around the mean. That assumption suits symmetric continuous noise—measurement error, natural variation around an average. When your outcome is roughly bell-shaped around the prediction, this is the right tool.

Binary outcomes call for a binomial or Bernoulli distribution. This is why logistic regression treats each prediction as a probability rather than a raw score. The distribution knows the outcome can only be 0 or 1, and it shapes the model's behavior accordingly.

Count data—number of events, purchases, clicks, claims—fits a Poisson distribution. The Poisson keeps predictions non-negative and, crucially, handles the fact that variance grows with the mean. Count data does not have constant spread. Days with more traffic also have more variable traffic. A normal distribution cannot capture that; a Poisson can.

The distribution choice changes how the model weights errors. If you fit a normal distribution to count data, the model treats a prediction of 50 with an observed value of 100 as a moderate miss. A Poisson-based model understands that when the mean is 50, seeing 100 is far more surprising—and weights that error accordingly.

In scikit-learn, this family is available through PoissonRegressor, GammaRegressor, and TweedieRegressor, which sit alongside LinearRegression in the linear model module.

Knowledge check

Check your understanding

Answer this question before you continue.

A team models daily numbers of customer clicks. On busier days, the average number of clicks and the variability both increase. Which response distribution best matches the article's recommendation?
Scenario Interpretation

Focus: Select a response distribution that reflects the nonnegative and mean-dependent variability of count data.

When a GLM Beats Ordinary Least Squares

Here is the decision rule I use: ask what the outcome can and cannot be, then pick the distribution and link that respect those constraints.

Use a GLM when the outcome is bounded, discrete, or skewed in a way a normal distribution cannot capture. The failure modes of forcing ordinary least squares onto such data are concrete and easy to spot.

Fit OLS to a binary outcome and you will get predictions below 0 or above 1. Those are meaningless as probabilities, yet the model will happily produce them. Fit OLS to count data and you will get negative predictions for things that cannot be negative—negative purchases, negative clicks—while also ignoring that the variance grows with the mean.

When is ordinary least squares still fine? When your outcome is continuous, roughly symmetric, and has no hard bounds. Temperature, height, test scores, profit margins—these fit the normal assumption well enough that a GLM adds complexity without adding much.

Note: The GLM framing is not about being fancy. It is about refusing to force data into a shape it does not have. Name the outcome's constraints first. Then choose the model that respects them.

Knowledge check

Check your understanding

Answer this question before you continue.

Which outcome is the clearest case for using a GLM rather than ordinary least squares?
Comparison Reasoning

Focus: Decide when a GLM is conceptually preferable to ordinary least squares based on outcome constraints.

Where the GLM Framework Stops Being Enough

Every framework has a boundary, and the GLM's is worth naming clearly.

A GLM is still linear in its parameters. It cannot learn feature interactions on its own, and it cannot model genuinely nonlinear feature effects. If the relationship between a feature and the outcome is curved—say, age and risk follow a U-shape—a GLM will miss it unless you manually add polynomial terms or interaction features.

The GLM's strength is interpretability and a principled match to the outcome type, not raw predictive flexibility. You get coefficients you can read and explain. You get a defensible statistical foundation. You do not get automatic discovery of complex patterns.

When the relationship between features and outcome is genuinely curved or interactive, tree-based models or other flexible approaches will often fit better. That is not a dismissal of GLMs. It is an honest boundary.

My rule: reach for a GLM when you want coefficients you can read, a principled match to the outcome type, and a strong baseline before trying more complex models. In many real projects, that baseline is good enough to ship.

The Practical Takeaway

Before you fit any model, name the outcome's constraints. Is it continuous and unbounded? Binary? A count that cannot go negative? Skewed so that variance grows with the mean?

Then choose the distribution and link that respect those constraints. Continuous and symmetric? Ordinary least squares. Binary? Logistic regression with a logit link. Count data? Poisson regression with a log link.

The GLM framework is not another algorithm to memorize. It is the connective tissue that shows you why these models exist and when each one earns its place. The engine is always the same linear predictor. The link function and response distribution are how you adapt that engine to the reality of your data.

Try it on your own data. Take a binary or count outcome you have been forcing through ordinary least squares, reframe it as a GLM, and watch what changes. The predictions will respect the outcome's constraints. The coefficients will still be readable. And the mental model you build from that exercise will serve you across every linear model you touch afterward.

Knowledge check

Final check

Finish the article by checking the ideas you just learned.

A risk outcome follows a U-shaped relationship with age, and the analyst has not added polynomial or interaction features. What limitation of a basic GLM matters most?
Question 1 of 2Scenario Interpretation

Focus: Recognize when a GLM's linear parameterization is insufficient for curved or interactive feature effects.

According to the article's practical workflow, what should you do first when choosing among linear-model approaches?
Question 2 of 2Comparison Reasoning

Focus: Apply the article's outcome-first workflow to choose a suitable model family, link, and distribution.

References

  1. sklearn.linear_model — scikit-learn 1.6.1 documentationscikit-learn.org
  2. Generalized Linear Model - an overviewwww.sciencedirect.com
8sources checked
8source domains
6searches run

Research updated Sep 8, 2026

Related sites

Continue across the AI learning path

Use LearnPyFast for Python foundations and LearnLLMFast when you are ready to move from classical ML into LLM applications.

Python tutorialstutorial

LearnPyFast

Beginner-friendly Python tutorials, examples, and learning paths for practical programming foundations.

PythonProgrammingBeginners
Visit LearnPyFast
LLM tutorialstutorial

LearnLLMFast

Practical LLM tutorials for builders who want to understand prompting, workflows, agents, and AI applications.

LLMAIBuilders
Visit LearnLLMFast

Keep learning

Related machine learning tutorials

Continue with nearby concepts, model families, evaluation methods, and practical workflows.