liveBook · Manning

Maximum likelihood estimation

As explained in Grokking Statistics

A parameter-estimation technique that selects parameter values maximizing the likelihood of the observed data.

Maximum likelihood estimation chooses the parameter values that make the observed data most likely. In logistic regression, it adjusts β₀ and β₁ to find the most plausible curve for the observed outcomes. section 8.3

Unlike least squares, this approach asks which curve most likely produced the data. The fitting mathematics stays mostly behind the library interface. section 8.3

A practical workflow looks like this:

  • Prepare predictor values as a column and pair them with binary outcomes. section 8.3
  • Fit LogisticRegression with scikit-learn, then inspect the learned coefficient and intercept. section 8.3
  • Use the fitted parameters to calculate or predict an outcome probability. section 8.3

Toddler meltdowns

Given hours without a nap and whether a meltdown occurred, maximum likelihood estimation fits a logistic curve. The resulting model predicts about a 0.9701 meltdown probability at 4.78 hours without a nap. section 8.3

import numpy as np
from sklearn.linear_model import LogisticRegression

x = np.array([0.1, 0.5, 0.7, 1.2, 1.2, 1.5, 1.6, 1.9, 2.5, 2.5,
              2.7, 3.2, 3.3, 3.7, 3.8, 4.1, 4.5, 4.5, 4.5, 5.0,
              5.1, 5.6, 5.7, 6.2, 6.3]) \
    .reshape(-1, 1)  #1

y = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
              0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
              1.0, 1.0, 1.0, 1.0, 1.0])  #2

model = LogisticRegression(penalty=None)  #3
model.fit(x, y)   #3

b1 = model.coef_.flatten()[0]  #4
b0 = model.intercept_[0]  #4
print(f"β₀={b0:.4f}, β₁={b1:.4f}")  #5

This listing shows the complete scikit-learn fitting workflow, including reshaping the predictor, fitting the model, and reading β₀ and β₁. section 8.3

How Grokking Statistics covers it

How deep it goes
Defines likelihood fitting and contrasts it with least squares, but defers the mathematical derivation to libraries.
Examples
Uses hours without a nap, toddler meltdown outcomes, a fitted curve, and a predicted probability at 4.78 hours.
What you can do after
Apply it via scikit-learn to fit logistic-regression parameters and predict probabilities from observed data.
How it connects
Connects maximum likelihood estimation with logistic regression, least squares, coefficients, intercepts, and overfitting.

Also explained in

Compare how 4 books explain maximum likelihood estimation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Statistics. The section links point to the parts of the book it draws on.