-
Book Overview & Buying
-
Table Of Contents
Machine Learning for Time Series with Python - Second Edition
By :
When organizations evaluate their analytics capabilities, they don't think about crystal balls or fortune telling—they think about dashboards, monitoring systems, and automated decision-making platforms. Time series analysis has evolved far beyond statistical forecasting to become the foundation for intelligent systems that power competitive advantage across every major industry. The question isn't whether to invest in temporal analytics, but how to build systems that work reliably when business decisions depend on them.
Python offers comprehensive coverage of time series techniques, from classical statistical methods to modern machine learning approaches, with libraries optimized for different types of problems and performance requirements. While other environments lock you into single approaches, Python enables strategic navigation across complementary libraries, each optimized for different aspects of production time series challenges.
Inside Python, the time series toolkit fans out across four problem types: forecasting, classification, anomaly detection, and regression.
These four overlap at the edges. A sensor classifier needs an anomaly detector for its unlabeled tail; a regression model gives you the levers a forecast needs to steer; an anomaly that recurs becomes a classifier candidate. Even so, each one foregrounds a distinct question. Forecasting asks what comes next. Classification asks what kind of pattern this is. Anomaly detection asks does this look like anything we've seen before. Regression asks what drives the target and by how much. Naming the question first is the cheapest decision in the project, and the one that determines which corner of the ecosystem the rest of the work lives in. The four sections below walk each problem type in turn, naming the production systems already running and the Python libraries the rest of this book draws on.
Forecasting predicts future values to drive planning. Mount Sinai Health System learned the value during COVID-19, when its demand models projected ventilator and ICU-bed needs three weeks ahead and let hospitals stage supplies before the peak hit. Pacific Gas and Electric runs the same pattern on the demand side, forecasting consumer electricity usage to set dynamic prices that shave peak load away.
The pattern repeats wherever a decision today depends on a number tomorrow. NextEra Energy fuses weather forecasts with historical generation to dispatch wind and solar hours in advance. Uber surge pricing scores thousands of concurrent series at sub-second latency. Amazon stages inventory across fulfillment centers, Netflix places content close to viewing demand, YouTube anticipates per-user engagement, Google rides temporal query patterns to keep search relevant as topics trend, and Tesla forecasts Supercharger usage to plan network expansion.
Python's forecasting stack reflects this breadth. statsmodels, sktime, and darts cover the classical baselines (ARIMA, exponential smoothing, state-space models) every credible project should benchmark against. Nixtla's statsforecast, neuralforecast, and mlforecast suite scale those ideas to thousands of series with global and hierarchical models, which is what teams reach for once one model has to serve every store, region, or SKU. AWS GluonTS adds probabilistic deep learning when point predictions stop being enough.
The 2026 frontier sits in foundation models like Amazon's Chronos-2 and Nixtla's TimeGPT, both introduced earlier in this chapter; they often beat handcrafted baselines without any retraining at all. Prophet still earns a place when monthly retail seasonality dominates, though reaching for it by default is the failure mode the Why advanced models still fail section warns against.
Classification labels temporal patterns so the right action fires automatically. The catch is that the label depends on the shape of the recent history, which is what separates time-series classification from a snapshot classifier looking at one row.
Johns Hopkins Hospital's Early Warning System reads multivariate vital signs to flag patients whose trajectories match septic-shock precursors, alerting clinicians hours before symptoms become obvious. On factory floors, 3M classifies temperature, pressure, and vibration patterns from production sensors to stop quality defects before they reach packaging, and General Electric monitors aircraft engines, wind turbines, and power plants the same way to schedule maintenance before components fail. Meta classifies temporal activity patterns in account behavior to identify fake accounts and coordinated abuse. Financial institutions classify transaction sequences to flag fraud across millions of daily payments without trapping legitimate customers in a wall of false declines.
sktime and aeon are the entry points for time-series classifiers across the major families (shapelet, dictionary-based, interval, deep). tslearn covers distance-based methods like dynamic time warping for cases where samples arrive on uneven timestamps.
tsfresh sits one layer up, turning a raw series into hundreds of summary statistics that feed scikit-learn or gradient-boosting pipelines when the goal is interpretable importance scores rather than end-to-end deep learning.
Anomaly detection flags observations whose pattern deviates enough from baseline to warrant attention, which is what separates a working monitor from one that drowns its operators in alerts.
Cybersecurity teams use it to spot network intrusions inside enterprise traffic; cloud providers use it to predict server failures from system-metric drift before customer impact; energy grid operators use it to catch equipment anomalies before they cascade into outages. The same lens applies to high-frequency trading, where signal extraction at the microsecond scale matters more than long-horizon planning. It also underwrites predictive maintenance whenever a defect signature has not yet been cataloged for a classifier. The open-set problem, where the unknowns dominate the knowns, is exactly the regime where 3M's quality monitors and GE's industrial-IoT platforms earn their keep.
Python tooling runs through PyOD for the broad catalog of detectors (isolation forest, autoencoder, copula-based, distance-based) and Merlion and Kats for production-monitoring framings that bundle detection with thresholding and root-cause hooks.
river handles online detection where points arrive one at a time and the model never sees the whole stream at once, and darts' anomaly-detection module fits in when a team is already invested in darts for forecasting and wants to share a single residual signal between the two.
Regression explores how external factors drive a target series, which is the right framing when the question is causal or counterfactual rather than what comes next.
Banks use it for Value-at-Risk models that project potential losses against millions of transactions while leaving the audit trail regulators demand for capital allocation. Marketing teams trace how campaigns move sales across channels and time horizons; urban planners measure how transit changes ripple into traffic and economic activity; central banks study how policy moves employment, inflation, and growth over time. Tesla's Autopilot is regression at its most demanding: cameras, radar, and ultrasonic sensors stream into models that predict how nearby vehicles will move next, and that is multivariate temporal regression even when the network underneath is a deep one.
Python here leans on scikit-learn and statsmodels for the parametric core that gives you coefficients, standard errors, and a story to tell a regulator.
causalimpact and DoWhy step in when the question is whether one series caused a change in another, providing the counterfactual machinery (synthetic controls, propensity weighting, instrumental variables) to make the answer defensible rather than a correlation dressed in temporal clothing.
In production, the four rarely live alone. GE runs predictive-maintenance pipelines that classify known failure signatures, then run anomaly detection on what is left and feed a forecasting model that schedules technician visits, all from the same telemetry stream. Uber's surge-pricing forecast feeds a classification model that decides which drivers to nudge into a busy zone. Mount Sinai's COVID forecasts drove a regression model on staff capacity, asking which interventions would change the trajectory most. Later chapters chain libraries along those seams. Python's advantage lives in multi-model systems no library was designed to own end-to-end.
Across forecasting, classification, anomaly detection, and regression a set of shared principles separates successful production systems from demos.
Meeting these multifaceted requirements is precisely where Python's ecosystem provides its strategic advantage. The ability to combine specialized libraries (statistical frameworks for interpretability, production libraries for efficiency, deep learning for complex patterns, and uncertainty tools for reliability) is what allows organizations to build temporal intelligence that drives real-world value.
Chapter 4 translates these principles into actionable criteria. The goal is to create adaptive systems that continue working reliably when temporal patterns inevitably change. Choosing the right tool requires understanding not just what is available but also recognizing the systematic failure patterns that derail even sophisticated implementations. Six critical patterns emerge consistently across industries and decades.
Change the font size
Change margin width
Change background colour