Generalized Linear Models › Common GLM Types

Michael BrenndoerferApril 1, 20258 min read
Machine Learning from ScratchAll chapters
Part 4 of 9Regression Models
Chapter 40Generalized Linear Models › Common GLM Types
Reading section 3 of 12 · Common GLM Types · 8 minSection 3 of 12 · 8 min

Book contents

Section 3 of 12 · 8 min read

Generalized Linear Models › Common GLM TypesOne section · Sections in this chapter3 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Each GLM type is defined by its choice of link function and probability distribution. The link function acts as a bridge between the linear predictor (the weighted sum of your features) and the expected value of the response variable. By selecting an appropriate link function and distribution, GLMs allow us to model a wide variety of data types using a unified framework.

In the following sections, we'll briefly introduce the most common GLM types: linear and logistic regression, followed by Poisson regression, to illustrate how the link function and model structure work together. Each of these models is covered in greater detail in its own dedicated chapter, where you'll find deeper mathematical explanations, practical examples, and implementation guidance. For now, consider this a high-level overview to set the stage for those more in-depth explorations.

Out[3]:
Visualization
Normal probability density filled in blue with a solid outline and a dashed coral identity-link line, with both definitions retained in a legend below the axes.
Normal distribution with identity link overlay. The bell-shaped curve represents continuous data that follows a Gaussian distribution, while the red dashed line shows the identity link function (μ = η) that directly maps the linear predictor to the expected response without transformation.
Two bars for fail and pass outcomes with an overlaid dashed coral logistic-link curve, with both series identified in a legend below the axes.
Binary outcomes with logistic link overlay. The bars show the frequency of binary outcomes (fail/pass), while the S-shaped red curve demonstrates the logit link function that maps the linear predictor to probabilities bounded between 0 and 1.
Poisson probability bars for counts zero through fourteen with an overlaid dashed coral exponential-link curve, with both definitions retained in a legend below the axes.
Count data with exponential link overlay. The histogram displays the Poisson distribution for count data, while the exponential curve (red dashed) shows the log link function (μ = e^η) that ensures predicted counts remain positive.

When the response variable is continuous and normally distributed, and the relationship between the predictors and the response is assumed to be linear, we use the identity link function. This is the classic linear regression model.

  • Distribution: Normal (Gaussian)
  • Link function: g(μ)=μg(\mu) = \mu (identity)
  • Model: μ=β0+β1x1+⋯+βpxp\mu = \beta_0 + \beta_1 x_1 + \cdots + \beta_p x_p

where:

  • μ=E[Y∣X]\mu = E[Y|X] is the expected value of the response variable YY given the predictors XX (the conditional mean we're modeling)
  • β0\beta_0 is the intercept (the expected response when all predictors equal zero)
  • β1,…,βp\beta_1, \ldots, \beta_p are the regression coefficients (quantify the linear effect of each predictor)
  • x1,…,xpx_1, \ldots, x_p are the predictor variables (the feature values)
  • pp is the number of predictors

The identity link means that the expected response is modeled directly as a linear function of the features. This is the standard linear regression we've covered in previous sections, and it is the basis for all GLMs.

When to use: Use linear regression when your outcome is continuous with no fixed bounds and follows an approximately normal distribution. Examples include predicting house prices, heights, or temperatures.

When the response variable is binary (e.g., success/failure, yes/no, 0/1), logistic regression is the appropriate GLM. It uses the logit link function to model the probability of success.

  • Distribution: Binomial
  • Link function: g(μ)=log⁡(μ1−μ)g(\mu) = \log\left(\frac{\mu}{1-\mu}\right) (logit)
  • Model: log⁡(p1−p)=β0+β1x1+⋯+βpxp\log\left(\frac{p}{1-p}\right) = \beta_0 + \beta_1 x_1 + \cdots + \beta_p x_p

where:

  • p=P(Y=1∣X)p = P(Y=1|X) is the probability that the response variable equals 1 (success) given predictors XX (the parameter we're modeling)
  • p1−p\frac{p}{1-p} is the odds of success (the ratio of the probability of success to the probability of failure)
  • log⁡(p1−p)\log\left(\frac{p}{1-p}\right) is the log-odds or logit (the natural logarithm of the odds)
  • β0\beta_0 is the intercept (the log-odds when all predictors equal zero)
  • β1,…,βp\beta_1, \ldots, \beta_p are the regression coefficients (represent the change in log-odds for a one-unit increase in each predictor)
  • x1,…,xpx_1, \ldots, x_p are the predictor variables (the feature values)

The logit link transforms probabilities (which are constrained to be between 0 and 1) to the entire real line, allowing us to model them with a linear predictor.

When to use: Use logistic regression for binary classification tasks, such as predicting whether a customer will buy a product (yes/no), or whether an email is spam (spam/not spam).

For modeling count data.where the response variable represents the number of times an event occurs.Poisson regression is used. It employs the log link function to ensure that the predicted counts are non-negative.

  • Distribution: Poisson
  • Link function: g(μ)=log⁡(μ)g(\mu) = \log(\mu) (log)
  • Model: log⁡(λ)=β0+β1x1+⋯+βpxp\log(\lambda) = \beta_0 + \beta_1 x_1 + \cdots + \beta_p x_p

where:

  • λ=E[Y∣X]\lambda = E[Y|X] is the expected count (mean of the Poisson distribution) given predictors XX (the rate parameter we're modeling)
  • log⁡(λ)\log(\lambda) is the natural logarithm of the expected count (the link function applied to the mean)
  • β0\beta_0 is the intercept (the log of the expected count when all predictors equal zero)
  • β1,…,βp\beta_1, \ldots, \beta_p are the regression coefficients (represent the change in log-count for a one-unit increase in each predictor)
  • x1,…,xpx_1, \ldots, x_p are the predictor variables (the feature values)

The log link ensures that the predicted mean is positive. By inverting the log link, we get:

λ=eβ0+β1x1+⋯+βpxp\lambda = e^{\beta_0 + \beta_1 x_1 + \cdots + \beta_p x_p}

where:

  • ee is Euler's number (approximately 2.718)
  • The exponential function exe^x is positive for any real value xx
  • This ensures λ>0\lambda > 0, which is necessary for count data (counts cannot be negative)

When to use: Use Poisson regression when your outcome is a count (e.g., number of customer visits, number of accidents, number of emails received in an hour), and the counts are non-negative integers.

Linear and logistic regression, together with Poisson regression, are the most common and foundational examples of GLMs. Each is defined by its choice of distribution and link function, allowing you to tailor the model to the nature of your response variable.

GLM Models

The models and link functions described above are all classic examples of Generalized Linear Models (GLMs). While this list is not exhaustive, these are among the most commonly used GLM types in practice. We will explore the mathematical details and reasoning behind the most popular forms and link functions in the following sections.