Generalized Linear Models › Formula

Michael BrenndoerferApril 1, 20255 min read
Machine Learning from ScratchAll chapters
Part 4 of 9Regression Models
Chapter 40Generalized Linear Models › Formula
Reading section 4 of 12 · Formula · 5 minSection 4 of 12 · 5 min

Book contents

Section 4 of 12 · 5 min read

Generalized Linear Models › FormulaOne section · Sections in this chapter4 / 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

The general GLM formula can be written as:

g(E[Y∣X])=β0+β1x1+β2x2+⋯+βpxpg(E[Y|X]) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots + \beta_p x_p

where:

  • E[Y∣X]E[Y|X] is the expected value of the response variable YY given the features XX (the conditional mean)
  • g(⋅)g(\cdot) is the link function (transforms the expected response to the linear predictor scale)
  • β0\beta_0 is the intercept term
  • β1,…,βp\beta_1, \ldots, \beta_p are the regression coefficients (one for each feature)
  • x1,x2,…,xpx_1, x_2, \ldots, x_p are the feature values (predictor variables)
  • pp is the number of features

This reads as: "The link function applied to the expected value of the response equals the linear combination of features with their coefficients."

Matrix Notation

In matrix form, the GLM can be written as:

g(μ)=Xβg(\boldsymbol{\mu}) = \mathbf{X}\boldsymbol{\beta}

where:

  • μ=E[Y]\boldsymbol{\mu} = E[\mathbf{Y}] is the vector of expected responses (one element per observation, where μ=[μ1,μ2,…,μn]T\boldsymbol{\mu} = [\mu_1, \mu_2, \ldots, \mu_n]^T and μi=E[Yi]\mu_i = E[Y_i])
  • X\mathbf{X} is the n×(p+1)n \times (p+1) design matrix of features (each row is one observation, each column is one feature, with the first column typically being all 1s for the intercept)
  • β\boldsymbol{\beta} is the (p+1)×1(p+1) \times 1 vector of coefficients (β=[β0,β1,…,βp]T\boldsymbol{\beta} = [\beta_0, \beta_1, \ldots, \beta_p]^T)
  • g(⋅)g(\cdot) is applied element-wise to μ\boldsymbol{\mu} (producing a vector where each element is g(μi)g(\mu_i))
  • nn is the number of observations

How GLM Components Work Together

The following diagram illustrates how the three components of a GLM connect to transform input features into predictions:

Out[4]:
Visualization
Flow diagram from input features X and coefficients beta through the systematic, link, and random GLM components, followed by three aligned example rows for linear, logistic, and Poisson regression and a note that the systematic component is always linear.
Architecture of Generalized Linear Models. The diagram shows the flow from input features through the three key components: (1) the systematic component creates a linear predictor η from features X and coefficients β, (2) the link function g(·) connects the linear predictor to the expected response μ, and (3) the random component specifies how the observed response Y is distributed around μ. This unified framework allows GLMs to model diverse response types while maintaining computational efficiency and interpretability.