
Linear and Generalized Linear Models
Linear models built from first principles: model fundamentals and diagnostics, OLS through polynomial and spline regression, ridge, lasso, and elastic net, then logistic, multinomial, and Poisson regression unified under the GLM framework. Likelihood, optimization, validation, additive and quantile models, and survival analysis complete the volume.
One part of Machine Learning from Scratch. The complete book remains free to read online; this paid edition is the carefully typeset PDF and companion notebook package you keep.
Become a confident machine learning practitioner.
Being confident in machine learning means being able to explain your choices. You can look at a dataset, recognise the assumptions behind a method, and decide whether the result is useful.
This book helps you build that judgment by connecting the mathematical ideas to worked examples and runnable Python. You can follow the reasoning, change the code, and see how the result responds.
See what you’ll learnUnderstand the models you choose
Work through linear models and their assumptions, then use diagnostics and regularization to make more informed modeling decisions.
Build understanding you can return to
Keep the explanations and companion notebooks beside you as you learn. When you meet a familiar problem in a new project, revisit the derivation and adapt the example with a clearer understanding of what it assumes.
Learning outcomes
What you will learn
- Derive linear regression from the loss function and diagnose when its assumptions fail.
- Build simple, multiple, polynomial, and spline regression models from first principles.
- Control variance with ridge, lasso, and elastic-net regularization.
- Choose and interpret logistic, multinomial, Poisson, and generalized linear models for different response types.
Audience and prerequisites
Who this volume is for
- Data scientists who want to understand regression beyond library calls.
- Machine-learning practitioners working with interpretable predictive models and structured data.
- Students preparing for advanced modeling, econometrics, or applied statistics.
Prerequisites: Assumes the statistical foundations and inference concepts covered in Volume 1.
Volume 2 PDF + code
Own this 961-page edition
Get the PDF, the runnable companion notebooks, and every future update and erratum for this volume. The corresponding online chapters stay free to read.
- Carefully typeset PDF
- Companion code for every included chapter
- Future updates and errata included
- Online chapters remain free to read
Volume 2 of 4
$24
one-timeVersion 2026.10.0 · 961 pages · secure checkout via Stripe
Delivered by email · Free updates included
Want the complete series?
All 4 volumes · 2,858 pages · complete companion code. Save $28 vs. buying all four separately.
Buy the complete book · $68Reader verdict
5.0
out of 5
12 five-star reader reviews
Genuine feedback, with names abbreviated for privacy.
Meet the community“I am enjoying reading your writings. I appreciate the effort you put into it. I want to drop a note of thanks. Thank you!”
“I would like to thank you for your work. Specifically, the chapter: 'LIME Explainability: Complete Guide to Local Interpretable Model-Agnostic Explanations' was extremely helpful for me in understanding LIME and communicating to colleagues. Your work is inspiring and valuable. Thank you for doing it.”
“I just came across your website where your books are available for free to read. Thank you so much for making this available to the public. This will help a lot of people.”
“I found your book Language AI Handbook's explanations of Transformer architectures and production deployment strategies to be exceptionally clear and insightful”
“Your writing feels like a treasure trove of great material. So, thank you for compiling everything on your website!”
“Really appreciate the way you have explained the concepts. Simple to understand, yet builds up knowledge exponentially, all while reinforcing it with examples repeatedly. I've read the last two chapters `74.Self-attention & 75.Q,K,V` and I've to admit, my concepts have never been clearer. You really are doing an amazing job breaking down maths and complex concepts like a story!”
“Thank you Michael. It's top!”
“I read a few of your blogs on NLP and oh WOW, they really are something, now I exactly know how all of the terms Entropy, Cross-entropy and how it is connected to Perplexity, will definitely read more of your blogs.”
“I came across your collection of online handbooks covering quantitative finance, AI, and machine learning. I wanted to reach out and thank you for making such high-quality material openly available. They are incredibly helpful for my CFA Level II review and for brushing up ahead of ML interviews.”
“Thanks so much for establishing such an amazing community. I appreciate the opportunity to be a learner and a contributor to the community.”
“Thanks for putting cool stuff out into the world.”
“I came across one of your books, Language AI Handbook, and man, I'm loving it. I've read many books but have never found such a comprehensive book on large models that covers everything from start to finish with such depth.”
Read all 12 reader reviews
“I would like to thank you for your work. Specifically, the chapter: 'LIME Explainability: Complete Guide to Local Interpretable Model-Agnostic Explanations' was extremely helpful for me in understanding LIME and communicating to colleagues. Your work is inspiring and valuable. Thank you for doing it.”
“Really appreciate the way you have explained the concepts. Simple to understand, yet builds up knowledge exponentially, all while reinforcing it with examples repeatedly. I've read the last two chapters `74.Self-attention & 75.Q,K,V` and I've to admit, my concepts have never been clearer. You really are doing an amazing job breaking down maths and complex concepts like a story!”
“Thanks so much for establishing such an amazing community. I appreciate the opportunity to be a learner and a contributor to the community.”
“I just came across your website where your books are available for free to read. Thank you so much for making this available to the public. This will help a lot of people.”
“I am enjoying reading your writings. I appreciate the effort you put into it. I want to drop a note of thanks. Thank you!”
“Thank you Michael. It's top!”
“Thanks for putting cool stuff out into the world.”
“I found your book Language AI Handbook's explanations of Transformer architectures and production deployment strategies to be exceptionally clear and insightful”
“Your writing feels like a treasure trove of great material. So, thank you for compiling everything on your website!”
“I came across your collection of online handbooks covering quantitative finance, AI, and machine learning. I wanted to reach out and thank you for making such high-quality material openly available. They are incredibly helpful for my CFA Level II review and for brushing up ahead of ML interviews.”
“I read a few of your blogs on NLP and oh WOW, they really are something, now I exactly know how all of the terms Entropy, Cross-entropy and how it is connected to Perplexity, will definitely read more of your blogs.”
“I came across one of your books, Language AI Handbook, and man, I'm loving it. I've read many books but have never found such a comprehensive book on large models that covers everything from start to finish with such depth.”
Exact contents
30 chapters across 4 parts
Every chapter below is included in the PDF and companion code. Links open the corresponding chapter in the free online edition.
Model Fundamentals and Diagnostics
Model Evaluation and Selection
Linear and Generalized Linear Models
- 01Simple Linear Regression
- 02Ordinary Least Squares (OLS)
- 03Multiple Linear Regression
- 04Polynomial Regression
- 05Spline Regression
- 06Generalized Additive Models
- 07Ridge Regularization (L2 Regularization)
- 08Lasso Regularization (L1 Regularization)
- 09Elastic Net Regularization
- 10Logistic Regression
- 11Multinomial Logistic Regression
- 12Poisson Regression
- 13Generalized Linear Models
- 14Quantile Regression
Survival Analysis
Choose the edition that fits your next step
Volume 2: Linear and Generalized Linear Models
Focus on Model Fundamentals and Diagnostics and Model Evaluation and Selection and Linear and Generalized Linear Models and Survival Analysis, with the explanations and code together in one edition.
961 pages · 30 chapters · companion notebooks
$24one-time
Choose this volumeThe complete Machine Learning from Scratch book
Keep the full series beside you as you progress from statistical foundations to models, forecasting, and optimization.
All 4 volumes · 2,858 pages · complete companion code
$68one-time
Get the complete bookBoth editions include future updates. Buying three distinct volumes also unlocks the complete book automatically.
Also in the series
Explore the other volumes

Volume 1 · 430 pages
Statistical Foundations and Hypothesis Testing
Statistical Foundations for Machine Learning · Hypothesis Testing

Volume 3 · 911 pages
Trees, Explainability, and Unsupervised Learning
Supervised Learning Beyond Linear Models · Tree-Based Models · Unsupervised Learning · Dimensionality Reduction · Model Interpretation · Calibration and Prediction Uncertainty

Volume 4 · 620 pages
Forecasting and Optimization
Time Series Forecasting · Constrained Optimization · Heuristic and Evolutionary Optimization
Version history
Kept current, not frozen in time
Each PDF purchase includes future editions. When the book changes, the updated copy appears in My books at no extra cost.
Current release
Edition 2026.10.0
Expanded from 66 to 92 chapters across 15 parts, with model evaluation, survival analysis, supervised learning, calibration, conformal prediction, forecasting validation, and heuristic optimization. Includes corrected original chapters, refreshed print navigation and typography, and updated companion code.
Earlier releases6
2026.08.2
Editorial improvements.
2026.08.1
Editorial refinements, restored plot typography, clearer logarithmic axes, and refreshed companion code.
2026.08.0
Editorial improvements throughout the book, with clearer explanations, refined presentation, improved plots and visualizations, and refreshed companion code.
2026.07.2
Improved companion notebooks and validation; removed the obsolete CLT appendix; updated the support contact.
2026.07.1
Validation edition bump: fixed typos in the SSE chapter.
2026.07.0
Initial public PDF and companion-code release.