2 Introduction
This book is written for the second graduate course in machine learning theory for students in the MS Applied Mathematics program. The focus is time series analysis and sequence data analysis: data whose order carries mathematical, statistical, and computational meaning.
Classical supervised learning often begins with independent examples
\[ (x_1,y_1),\ldots,(x_n,y_n), \]
where shuffling the rows usually does not change the problem. Time series and sequence data are different. A sequence
\[ X_1,X_2,\ldots,X_n \]
has memory. The past changes what we believe about the future, and the order of observations is part of the information.
A single observed time series
\[ x_1,x_2,\ldots,x_n \]
is viewed as one realization of a stochastic process
\[ \{X_t:t\in T\}. \]
In this book, most models use discrete time, so \(T=\mathbb{Z}\) or \(T=\{1,2,\ldots,n\}\), and most observations take values in \(\mathbb{R}\) or \(\mathbb{R}^d\). This includes scalar time series, multivariate time series, panel time series, and more general ordered sequence data.
A time series model is not only a curve-fitting method. It is a mathematical description of how information evolves through time.
2.1 Why time series and sequence data matter
Modern data science, machine learning, and AI systems increasingly depend on ordered data:
- financial prices, returns, volatility, and risk indicators;
- climate, weather, and environmental measurements;
- electricity demand, traffic, ridership, and sensor networks;
- biomedical signals, patient monitoring, and longitudinal health records;
- speech, text, video, and other sequential media;
- user behavior, recommendation logs, and event streams;
- scientific simulations and dynamical systems.
The central problem is not always forecasting. Sometimes the goal is to estimate dependence, detect hidden periodicity, identify structural change, denoise a signal, classify a sequence, discover regimes, learn representations, or build an AI model that can reason over long context.
2.2 Three viewpoints
The book develops three complementary viewpoints.
2.2.1 1. The time-domain viewpoint
The time-domain viewpoint models the present using past observations and past shocks. A simple autoregressive model is
\[ X_t=\phi X_{t-1}+W_t, \]
where \(\{W_t\}\) is white noise. More generally, ARMA and ARIMA models use equations such as
\[ \phi(B)X_t=\theta(B)W_t, \]
or
\[ \phi(B)(1-B)^dX_t=\theta(B)W_t, \]
where \(B\) is the backshift operator, \(BX_t=X_{t-1}\). This viewpoint emphasizes stationarity, autocovariance, autocorrelation, prediction, estimation, diagnostics, and model selection.
2.2.2 2. The frequency-domain viewpoint
The frequency-domain viewpoint studies how different oscillations contribute to variation in a series. A periodic component can be written as
\[ A\cos(2\pi\omega t+\varphi), \]
where \(\omega\) is the frequency, \(1/\omega\) is the period, \(A\) is the amplitude, and \(\varphi\) is the phase. Spectral analysis replaces the question “how does \(X_t\) depend on \(X_{t-h}\)?” with the question “which frequencies explain the variance?”
For a stationary process with autocovariance function \(\gamma(h)\), the spectral density is formally
\[ f(\omega)=\sum_{h=-\infty}^{\infty}\gamma(h)e^{-2\pi i\omega h}. \]
This viewpoint leads naturally to the discrete Fourier transform, FFT, periodogram, filtering, and wavelet analysis.
2.2.3 3. The representation-learning viewpoint
Modern sequence learning uses neural networks to learn nonlinear representations from ordered data. A windowed forecasting model may take the form
\[ \widehat X_{t+1:t+H}=f_\Theta(X_{t-L+1:t}), \]
where \(L\) is the input length, \(H\) is the forecast horizon, and \(f_\Theta\) may be an MLP, CNN, RNN, LSTM, GRU, temporal convolutional network, transformer, or representation-learning model.
This viewpoint connects time series analysis with deep learning, attention, self-supervision, anomaly detection, and modern AI-assisted modeling.
2.3 Forecasting as conditional prediction
One mathematical theme appears throughout the book: forecasting is a conditional prediction problem.
If \(\mathcal{F}_t\) denotes the information available at time \(t\), then the optimal mean-square forecast of \(X_{t+h}\) is
\[ \widehat X_{t+h|t}=E[X_{t+h}\mid \mathcal{F}_t]. \]
In practice, we often restrict attention to a class of models. Classical linear prediction uses projections onto past observations. Machine learning models use learned nonlinear functions of lagged features. Deep sequence models learn hidden states or attention weights. In all cases, the model must respect the information set: a valid forecast may use the past, but not the future.
For a forecasting problem, every preprocessing step, feature, validation split, and model input must be available at the forecast origin. If a method uses future information, its reported performance is not a valid estimate of forecasting performance.
2.4 What makes this book modern
This book keeps the mathematical core of time series analysis while expanding toward current machine learning and AI practice.
The classical core includes:
- stochastic process notation;
- stationarity and autocovariance;
- sample ACF and PACF;
- AR, MA, ARMA, ARIMA, and SARIMA models;
- best linear prediction;
- likelihood, AIC, BIC, and diagnostics;
- spectral density, FFT, periodogram, filtering, and wavelets.
The modern machine learning layer includes:
- leakage-aware feature engineering;
- rolling-origin validation and backtesting;
- automated forecasting and Prophet-type additive models;
- probabilistic forecasting and conformal prediction;
- neural networks for time series;
- CNNs, TCNs, RNNs, LSTMs, GRUs, and transformers;
- representation learning, anomaly detection, and multivariate forecasting;
- AI-assisted modeling, code review, model criticism, and project reporting.
2.5 How the chapters are organized
The book has seven parts.
Part I: Time Series as Dependent Data introduces stochastic processes, realizations, exploratory analysis, trend, seasonality, smoothing, and differencing.
Part II: Stationarity and Linear Time-Domain Models develops stationarity, autocorrelation, AR/MA/ARMA models, difference equations, best linear prediction, estimation, and diagnostics.
Part III: Nonstationary and Seasonal Models studies ARIMA, SARIMA, state-space models, Kalman filtering, hidden Markov models, and regime switching.
Part IV: Frequency-Domain and Multiresolution Methods develops spectral analysis, DFT, FFT, periodograms, filters, and wavelets.
Part V: Forecasting at Scale and Machine Learning Methods covers evaluation, backtesting, automated forecasting, feature-based machine learning, and probabilistic forecasting.
Part VI: Deep Learning for Time Series and Sequence Data introduces neural networks, convolutional sequence models, recurrent models, attention, transformers, representation learning, and multivariate sequence modeling.
Part VII: Responsible AI, Projects, and Deployment focuses on AI-assisted modeling, end-to-end pipelines, deployment monitoring, and the final project.
2.6 Interactive HTML modules
Each chapter includes interactive HTML demonstrations. These are designed to help students connect formulas with behavior:
- moving roots and observing stationarity or causality;
- changing AR and MA parameters and watching ACF patterns;
- adjusting trend, seasonality, and noise;
- exploring Fourier frequencies and periodograms;
- visualizing convolutional receptive fields;
- inspecting RNN hidden states and attention heatmaps;
- testing leakage-aware validation plans.
The interactive modules use Plotly. Plotly.js is loaded once globally through assets/header.html; individual chapter files should not load Plotly again. This keeps the book lighter and prevents duplicate JavaScript conflicts.
2.7 Python labs and Google Colab
Each chapter has a companion Python lab. The labs are designed to be opened in Google Colab from the GitHub repository:
https://github.com/wanghemath/Book-MachineLearning2sda
The labs emphasize reproducible computation:
- simulate models before fitting them;
- compare theory with empirical estimates;
- check baselines before complex models;
- use chronological validation;
- diagnose residuals and forecast errors;
- document assumptions and limitations.
The main Python stack is numpy, pandas, matplotlib, scipy, statsmodels, scikit-learn, plotly, and torch for the deep learning chapters.
2.8 Responsible use of AI
AI tools can help students write code, debug errors, explain diagnostics, generate alternative modeling ideas, and improve project reports. But AI tools can also produce invalid models, data leakage, incorrect formulas, or misleading interpretations.
Throughout the book, AI is used as an assistant, not as an authority. Students are expected to verify AI-generated work mathematically and computationally.
A useful AI-assisted modeling workflow is:
- State the forecasting or sequence-learning problem precisely.
- Identify the information set available at the forecast origin.
- Build simple baselines.
- Ask AI for candidate models and possible failure modes.
- Implement and test models carefully.
- Diagnose residuals, forecast errors, and validation design.
- Ask AI to critique the report.
- Verify every claim with code, mathematics, or evidence.
No AI-generated explanation, formula, code block, or modeling recommendation should be accepted unless it can be checked against the data, the mathematics, or a reproducible computation.
2.9 Mathematical preparation
Students should be comfortable with:
- linear algebra, especially projections, matrices, eigenvalues, and least squares;
- probability, especially expectation, variance, covariance, conditional expectation, and Gaussian distributions;
- statistical inference, especially estimation, likelihood, confidence intervals, and hypothesis testing;
- calculus and optimization, especially gradients and loss minimization;
- basic Python programming.
Some chapters use complex numbers, Fourier series, and matrix recursions. These topics are introduced when needed, but students should expect the book to use mathematical notation seriously.
2.10 Computational preparation
Students should be able to read and modify Python notebooks. The labs use a consistent pattern:
- import packages;
- simulate or load data;
- visualize the series;
- define the model or feature construction;
- fit the model;
- evaluate by chronological validation;
- diagnose errors;
- summarize findings.
The goal is not just to run code. The goal is to understand why the code corresponds to the mathematical model.
2.11 A first example: dependence changes prediction
Suppose \(\{W_t\}\) is white noise with mean zero and variance \(\sigma^2\). Then
\[ E[W_{t+1}\mid W_t,W_{t-1},\ldots]=0. \]
Past white noise does not help predict future white noise.
Now consider the AR(1) model
\[ X_{t+1}=\phi X_t+W_{t+1}. \]
Then
\[ E[X_{t+1}\mid X_t,X_{t-1},\ldots]=\phi X_t. \]
The past matters because the process has dependence. This simple contrast explains why time series analysis begins with dependence, stationarity, and autocorrelation.
2.12 What students should be able to do after this book
By the end of the book, students should be able to:
- explain why time dependence changes statistical learning;
- distinguish trend, seasonality, stationarity, and serial dependence;
- derive and interpret autocovariance and autocorrelation functions;
- build ARMA, ARIMA, SARIMA, state-space, and HMM-type models;
- use spectral and wavelet methods to analyze periodic and transient behavior;
- evaluate forecasts using rolling-origin validation and appropriate metrics;
- construct leakage-safe machine learning features for time series;
- build neural, convolutional, recurrent, and transformer-based sequence models;
- produce point forecasts, interval forecasts, and probabilistic forecasts;
- use AI tools responsibly as part of a reproducible modeling workflow;
- complete an end-to-end sequence-data project with mathematical explanation, code, diagnostics, and communication.
2.13 Suggested way to study
Read each chapter in four passes.
First, read the motivating example and the main definitions. Second, work through the mathematical derivations. Third, run the Python lab and change the parameters. Fourth, use the AI-assisted prompts to critique your own understanding.
Time series analysis is best learned by moving between theory, simulation, visualization, and real data. A formula explains what should happen; simulation shows whether the intuition is right; diagnostics reveal what the model missed.