Machine Learning from Scratch, Volume 4: Forecasting and Optimization cover

Volume 4 of 4 · PDF edition

Forecasting and Optimization

Time series forecasting from classical ETS and SARIMA through Prophet to neural N-BEATS and N-HiTS, then optimization for decision-making taught through five real operational case studies: factory planning, warehouse slotting, portfolio construction, rostering, and vehicle routing. Baselines, time-aware backtesting, formulation, local search, and evolutionary methods connect evaluation to the search for useful decisions.

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.

620 pages across 15 chaptersVersion 2026.10.0$24 one-time

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 learn

Reason about time and optimization

Develop a clearer understanding of forecasting and optimization, including the choices that influence how a model learns.

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

  • Model time-dependent structure and compare ETS, SARIMA, Prophet, N-BEATS, and N-HiTS forecasts.
  • Design honest forecasting evaluations that respect temporal order and operational constraints.
  • Translate business decisions into mixed-integer, flow, quadratic, constraint-programming, and routing models.
  • Implement optimization case studies for planning, slotting, portfolios, rostering, and vehicle routing.

Audience and prerequisites

Who this volume is for

  • Data scientists moving from prediction to forecasting and prescriptive decision-making.
  • Operations-research and analytics practitioners solving constrained planning problems.
  • Engineers who want end-to-end examples connecting models to operational decisions.

Prerequisites: Assumes comfort with regression and model evaluation from the earlier volumes; the optimization chapters are self-contained case studies.

Volume 4 PDF + code

Own this 620-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 4 of 4

$24

one-time

Version 2026.10.0 · 620 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 · $68

Reader 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!”
Krishnan S.Researcher
“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.”
Will G.Data Scientist
“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.”
Vikas C.AI/ML Engineer
“I found your book Language AI Handbook's explanations of Transformer architectures and production deployment strategies to be exceptionally clear and insightful”
San Z.Researcher
“Your writing feels like a treasure trove of great material. So, thank you for compiling everything on your website!”
Griffin P.Quantitative Researcher
“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!”
Muhammad H.AI/ML Engineer
“Thank you Michael. It's top!”
David X.Data Scientist
“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.”
Kanishk K.Reader
“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.”
Karim Z.Reader
“Thanks so much for establishing such an amazing community. I appreciate the opportunity to be a learner and a contributor to the community.”
Cyrille L.AI/ML Engineer
“Thanks for putting cool stuff out into the world.”
Charlie B.Applied AI
“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.”
Uon L.Reader
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.”
Will G.Data Scientist
“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!”
Muhammad H.AI/ML Engineer
“Thanks so much for establishing such an amazing community. I appreciate the opportunity to be a learner and a contributor to the community.”
Cyrille L.AI/ML Engineer
“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.”
Vikas C.AI/ML Engineer
“I am enjoying reading your writings. I appreciate the effort you put into it. I want to drop a note of thanks. Thank you!”
Krishnan S.Researcher
“Thank you Michael. It's top!”
David X.Data Scientist
“Thanks for putting cool stuff out into the world.”
Charlie B.Applied AI
“I found your book Language AI Handbook's explanations of Transformer architectures and production deployment strategies to be exceptionally clear and insightful”
San Z.Researcher
“Your writing feels like a treasure trove of great material. So, thank you for compiling everything on your website!”
Griffin P.Quantitative Researcher
“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.”
Karim Z.Reader
“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.”
Kanishk K.Reader
“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.”
Uon L.Reader

Exact contents

15 chapters across 3 parts

Every chapter below is included in the PDF and companion code. Links open the corresponding chapter in the free online edition.

Choose the edition that fits your next step

Focused edition

Volume 4: Forecasting and Optimization

Focus on Time Series Forecasting and Constrained Optimization and Heuristic and Evolutionary Optimization, with the explanations and code together in one edition.

620 pages · 15 chapters · companion notebooks

Best valueSave $28 vs. buying all four separately

The 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

Both editions include future updates. Buying three distinct volumes also unlocks the complete book automatically.

Also in the series

Explore the other volumes

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
  1. 2026.08.2

    Editorial improvements.

  2. 2026.08.1

    Editorial refinements, restored plot typography, clearer logarithmic axes, and refreshed companion code.

  3. 2026.08.0

    Editorial improvements throughout the book, with clearer explanations, refined presentation, improved plots and visualizations, and refreshed companion code.

  4. 2026.07.2

    Improved companion notebooks and validation; removed the obsolete CLT appendix; updated the support contact.

  5. 2026.07.1

    Validation edition bump: fixed typos in the SSE chapter.

  6. 2026.07.0

    Initial public PDF and companion-code release.