Mathematical and Statistical FoundationsIntroductionMachine learning is applied mathematics expressed through data and computation. A model represents relationships using functions; training estimates parameters; and prediction applies the learned function to new observations. The mathematical foundations in this chapter provide the language for representing data, measuring uncertainty, defining error, and improving a model. A useful working perspective is: 1. Linear algebra represents data and parameters. 2. Functions describe transformations and predictions. 3. Calculus measures how model outputs change. 4. Probability and statistics describe uncertainty and evidence. 5. Optimization selects parameters that minimize a defined loss. These ideas are not separate topics. For example, linear regression uses vectors and matrices to represent data, a function to produce predictions, a loss function to measure error, and derivatives with gradient descent to estimate parameters. Learning ObjectivesBy the end of this chapter, students should be able to: - Represent observations, features, parameters, and datasets using vectors and matrices.
- Perform and interpret basic vector and matrix operations.
- Explain functions, derivatives, gradients, and the chain rule in machine-learning contexts.
- Distinguish probability, likelihood, conditional probability, and posterior probability.
- Calculate and interpret descriptive statistics and common probability distributions.
- Apply Bayes’ theorem to a classification or diagnostic problem.
- Formulate an optimization problem and use gradient descent to reduce a loss function.
- Recognize assumptions, limitations, numerical issues, and responsible-use concerns.
1. Data Representation with Vectors and Matrices1.1 Scalars, vectors, and matricesA scalar is a single number, such as a temperature or a model parameter. A vector is an ordered list of numbers. A feature vector for one customer might be \[ x = \begin{bmatrix} 35 \\ 52000 \\ 3 \end{bmatrix}, \] where the entries could represent age, annual income, and number of previous purchases. The vector has dimension 3. The meaning of each position must remain consistent across observations. A matrix is a rectangular array. If a dataset contains n observations and p features, its design matrix is commonly written as \[ X \in \mathbb{R}^{n\times p}. \] The element \(x_{ij}\) is the value of feature j for observation i. A target vector is often written as \(y\in\mathbb{R}^{n}\). In supervised learning, rows usually represent examples and columns represent features, although software conventions may differ. An intercept can be included by adding a column of ones to X. Thus, a model with two features may use \[ \tilde X = \begin{bmatrix}1 & x_{11} & x_{12}\\1 & x_{21} & x_{22}\\\vdots & \vdots & \vdots\end{bmatrix}. \] 1.2 Operations and interpretationVectors of equal dimension can be added element by element. Scalar multiplication multiplies every component. The dot product of vectors a and b is \[ a^Tb=\sum_{j=1}^{p}a_jb_j. \] It produces a scalar and is central to linear prediction. A linear model is \[ \hat y = w^Tx+b, \] where w is a parameter vector, b is an intercept, and x is a feature vector. The units of each product \(w_jx_j\) must be compatible with the output units. The Euclidean norm measures vector length: \[ \|x\|_2=\sqrt{\sum_{j=1}^{p}x_j^2}. \] The distance between observations x and z is \(\|x-z\|_2\). This distance is meaningful only when feature scales are comparable or have been appropriately standardized. Matrix multiplication is defined when the inner dimensions agree. If \(A\) is \(m\times n\) and \(B\) is \(n\times r\), then AB is \(m\times r\), with \[ (AB)_{ij}=\sum_{k=1}^{n}A_{ik}B_{kj}. \] Matrix multiplication is generally not commutative: AB need not equal BA. The transpose \(A^T\) exchanges rows and columns. A square matrix is invertible only under conditions such as having full rank and a nonzero determinant. In practical machine learning, directly computing an inverse is often less stable and less efficient than solving a linear system using a numerical factorization. 1.3 Linear regression in matrix formFor n observations and p features, linear regression predicts \[ \hat y=Xw, \] where an intercept is included in X if required. A common objective is the residual sum of squares, \[ J(w)=\frac{1}{2n}\|Xw-y\|_2^2. \] The factor \(1/(2n)\) is a convention that simplifies derivatives; it does not change the minimizer. If X has full column rank, the ordinary least-squares solution satisfies the normal equations \[ X^TXw=X^Ty, \] and, when \(X^TX\) is invertible, \[ w=(X^TX)^{-1}X^Ty. \] This closed-form expression is mainly pedagogical or suitable for small well-conditioned problems. For large or poorly conditioned datasets, QR or singular-value decompositions, regularization, or iterative optimization are usually preferable. 2. Functions, Derivatives, and GradientsA function maps inputs to outputs. In machine learning, a model may be written \(f_\theta(x)\), where θ denotes all adjustable parameters. A loss function \(L(y,f_\theta(x))\) measures disagreement between the target and prediction. 2.1 DerivativesFor a one-variable function f, the derivative at x is \[ f'(x)=\lim_{h\to0}\frac{f(x+h)-f(x)}{h}, \] when the limit exists. It represents the instantaneous rate of change. If \(f'(x)>0\), a small increase in x locally increases f; if it is negative, f locally decreases. Important rules include \[ \frac{d}{dx}x^k=kx^{k-1},\qquad \frac{d}{dx}(c f)=c f', \] and the product rule \((fg)'=f'g+fg'\). The chain rule states that if \(q(x)=g(f(x))\), then \[ q'(x)=g'(f(x))f'(x). \] The chain rule is essential for backpropagation because a neural network is a composition of functions. For a multivariable function, the gradient collects partial derivatives: \[ \nabla J(w)=\begin{bmatrix}\partial J/\partial w_1\\\cdots\\\partial J/\partial w_p\end{bmatrix}. \] The gradient points in the direction of steepest local increase under the Euclidean metric. Consequently, the negative gradient is a local direction of decrease. 2.2 Example: derivative of squared lossFor one observation, let \[ J(w)=\frac{1}{2}(wx-y)^2. \] Using the chain rule, \[ \frac{dJ}{dw}=(wx-y)x. \] The term \(wx-y\) is the residual. If the residual and x have the same sign, increasing w increases the loss locally; if they have opposite signs, increasing w decreases it. For the dataset objective \(J(w)=\frac{1}{2n}\|Xw-y\|^2\), the gradient is \[ \nabla J(w)=\frac{1}{n}X^T(Xw-y). \] This formula assumes the squared Euclidean loss and real-valued parameters. It is valid whether or not X has full rank, although the minimizer may not be unique when columns are linearly dependent. 2.3 Convexity and stationary pointsA differentiable function is convex if its graph lies below the line segment joining any two points on the graph. For a convex optimization problem, every local minimum is a global minimum. Squared-error linear regression is convex in w. Neural-network training is generally non-convex, so gradient-based methods can encounter saddle points, flat regions, or multiple local structures. A stationary point satisfies \(\nabla J(w)=0\). A stationary point is not automatically a minimum; it may be a maximum or saddle point. Curvature, represented in twice-differentiable cases by the Hessian matrix of second derivatives, provides additional information. 3. Descriptive StatisticsDescriptive statistics summarize observed data but do not, by themselves, establish causal relationships. For values \(x_1,\ldots,x_n\), the sample mean is \[ \bar x=\frac{1}{n}\sum_{i=1}^{n}x_i. \] The median is the middle ordered value, or the average of the two middle values when n is even. The mean is sensitive to extreme values; the median is more robust to skewed distributions. The population variance is \(\sigma^2=E[(X-\mu)^2]\). For a sample used to estimate population variability, the usual unbiased sample variance is \[ s^2=\frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar x)^2, \] provided the observations are independently sampled under the standard assumptions. The sample standard deviation is \(s=\sqrt{s^2}\), in the same units as x. The range is maximum minus minimum. Quartiles divide ordered data into four sections, and the interquartile range is \(IQR=Q_3-Q_1\). The IQR is relatively resistant to outliers. A z-score is \[ z=\frac{x-\mu}{\sigma}, \] or, in a sample standardization, \((x-\bar x)/s\). It expresses distance from the mean in standard-deviation units. Standardization is often useful for optimization, but it must be fitted on training data only to avoid leakage. Covariance between random variables X and Y is \[ \operatorname{Cov}(X,Y)=E[(X-E[X])(Y-E[Y])]. \] The correlation is \[ \rho_{XY}=\frac{\operatorname{Cov}(X,Y)}{\sigma_X\sigma_Y}, \] when both standard deviations are positive. Correlation is dimensionless and lies between -1 and 1. It measures linear association, not causation, and a value near zero does not rule out nonlinear dependence. 4. Probability and DistributionsA probability model assigns values between 0 and 1 to events. For a discrete random variable, a probability mass function (PMF) gives \(P(X=x)\), and the probabilities over all possible values sum to 1. For a continuous variable, a probability density function (PDF) satisfies \[ P(a\le X\le b)=\int_a^b f(x)\,dx, \] and \(P(X=x)=0\) for an individual point under an ordinary continuous distribution. A cumulative distribution function is \(F(x)=P(X\le x)\). The expected value is a probability-weighted average. For a discrete variable, \[ E[X]=\sum_x xP(X=x), \] and for a continuous variable, \[ E[X]=\int_{-\infty}^{\infty}xf(x)\,dx, \] when the relevant sum or integral exists. Variance is \(\operatorname{Var}(X)=E[(X-E[X])^2]\). 4.1 Important distributionsA Bernoulli random variable represents one trial with success probability p: \(P(X=1)=p\) and \(P(X=0)=1-p\). Its mean is p and variance is \(p(1-p)\). A binomial variable counts successes in n independent Bernoulli trials with common success probability p: \[ P(X=k)=\binom nk p^k(1-p)^{n-k},\quad k=0,\ldots,n. \] Its mean is np and variance is \(np(1-p)\). Independence and constant p are assumptions of this model. The normal distribution with mean μ and variance \(\sigma^2>0\) has density \[ f(x)=\frac{1}{\sigma\sqrt{2\pi}}\exp\left[-\frac{(x-\mu)^2}{2\sigma^2}\right]. \] It is symmetric and often useful as an approximation or noise model, but many real variables are skewed or heavy-tailed. The standard normal has μ = 0 and σ = 1. The categorical distribution models one outcome among K categories with probabilities \(p_1,\ldots,p_K\), where \(p_k\ge0\) and \(\sum_kp_k=1\). It underlies multiclass classification. A model commonly converts scores to probabilities using softmax: \[ p_k=\frac{e^{z_k}}{\sum_{j=1}^{K}e^{z_j}}. \] For numerical stability, implementations subtract \(\max_j z_j\) from all scores before exponentiation; this does not change the probabilities. 5. Conditional Probability, Bayes’ Theorem, and LikelihoodThe conditional probability of A given B, when \(P(B)>0\), is \[ P(A\mid B)=\frac{P(A\cap B)}{P(B)}. \] Events A and B are independent when \(P(A\cap B)=P(A)P(B)\), equivalently when conditioning on one does not change the probability of the other, provided the relevant probabilities are defined. Bayes’ theorem follows from the definition of conditional probability: \[ P(A\mid B)=\frac{P(B\mid A)P(A)}{P(B)}. \] For mutually exclusive and exhaustive hypotheses \(A_1,\ldots,A_K\), \[ P(A_i\mid B)=\frac{P(B\mid A_i)P(A_i)}{\sum_{j=1}^{K}P(B\mid A_j)P(A_j)}. \] In machine learning, with parameter θ, data D, and prior distribution \(p(\theta)\), \[ p(\theta\mid D)=\frac{p(D\mid\theta)p(\theta)}{p(D)}. \] Here \(p(\theta\mid D)\) is the posterior, \(p(D\mid\theta)\) is the likelihood viewed as a function of θ, and \(p(\theta)\) is the prior. The likelihood is not generally a probability distribution over θ; it evaluates how compatible observed data are with different parameter values. For independent observations, the likelihood is commonly factorized as \[ L(\theta;D)=\prod_{i=1}^{n}p(y_i\mid x_i,\theta). \] Maximizing likelihood is equivalent to maximizing log-likelihood because the logarithm is strictly increasing. Products become sums: \[ \ell(\theta)=\sum_{i=1}^{n}\log p(y_i\mid x_i,\theta). \] For binary classification, if \(y_i\in\{0,1\}\) and the model predicts \(p_i=P(Y=1\mid x_i)\), the negative log-likelihood is binary cross-entropy: \[ J=-\frac1n\sum_{i=1}^{n}[y_i\log p_i+(1-y_i)\log(1-p_i)]. \] Probabilities must lie strictly between 0 and 1 for finite logarithms; implementations clip probabilities or, preferably, use numerically stable loss functions based on logits. Worked Bayes exampleSuppose 2% of transactions are fraudulent. A screening rule flags 90% of fraudulent transactions and incorrectly flags 5% of legitimate transactions. Let F denote fraud and + denote a flag. Then \[ P(F\mid +)=\frac{P(+\mid F)P(F)}{P(+\mid F)P(F)+P(+\mid F^c)P(F^c)} \] \[ =\frac{0.90(0.02)}{0.90(0.02)+0.05(0.98)} =\frac{0.018}{0.067}\approx0.269. \] Thus, a flagged transaction has approximately a 26.9% fraud probability, not 90%. The base rate is essential. 6. Optimization and Gradient DescentAn optimization problem specifies an objective and the variables to be selected. In supervised learning, \[ \min_\theta J(\theta)=\frac1n\sum_{i=1}^{n}L(y_i,f_\theta(x_i)). \] The loss should reflect the application: squared error is common for continuous targets, while cross-entropy is common for probabilistic classification. 6.1 Batch gradient descentWith learning rate \(\eta>0\), batch gradient descent updates \[ \theta_{t+1}=\theta_t-\eta\nabla J(\theta_t). \] The learning rate controls step size. If it is too small, training is slow; if too large, the objective may oscillate or diverge. The update is not guaranteed to reach a global optimum for non-convex objectives. For the one-variable loss \(J(w)=\frac12(wx-y)^2\), take x = 2, y = 6, and initial w = 1. The prediction is 2, the residual is -4, and the derivative is \[ (wx-y)x=(-4)(2)=-8. \] With learning rate \(\eta=0.1\), \[ w_{ ext{new}}=1-0.1(-8)=1.8. \] The new prediction is 3.6, closer to 6. This single update does not prove convergence; repeated updates and a suitable learning rate are required. 6.2 Stochastic and mini-batch methodsBatch gradient descent uses all training observations per update. Stochastic gradient descent uses one observation, and mini-batch gradient descent uses a subset. Mini-batches provide computational efficiency and noisy but often useful gradient estimates. Random shuffling, appropriate batch sizes, learning-rate schedules, and monitoring of validation performance are standard practices. Regularization modifies the objective to discourage overly complex parameters. Ridge regression uses \[ J(w)=\frac{1}{2n}\|Xw-y\|^2+\lambda\|w\|_2^2, \] where \(\lambda\ge0\). If the penalty is exactly \(\lambda\|w\|_2^2\), its gradient contribution is \(2\lambda w\). Some texts define the penalty as \((\lambda/2)\|w\|_2^2\), whose gradient is \(\lambda w\); the convention must be stated. The intercept is often excluded from regularization. Regularization can reduce variance but may increase bias. 7. Illustrative Case: Predicting Customer ChurnBackground and problemA subscription company wants to identify customers at risk of cancellation. Available features include tenure, monthly fee, support contacts, and recent usage. The business intends to prioritize retention offers, not automatically terminate accounts. AnalysisThe data team represents each customer as a feature vector and forms a design matrix. Monetary and usage variables have different scales, so scaling parameters are estimated from the training set and applied unchanged to validation and test sets. Exploratory summaries identify missing values, skewness, outliers, and class imbalance. A random split would be inappropriate if multiple records from the same customer or future information appear in both sets; leakage would produce overly optimistic results. ApproachA baseline logistic-regression classifier estimates churn probability. Its likelihood is Bernoulli, and training minimizes binary cross-entropy, possibly with L2 regularization. The decision threshold is selected using the relative costs of contacting a customer and missing a likely churner. Accuracy alone is insufficient when churn is uncommon; precision, recall, calibration, and expected business cost are examined. Bayesian reasoning helps interpret alerts. Even a model with strong sensitivity may produce many false positives when the base rate is low. Calibration checks whether, for example, customers assigned probabilities near 0.30 churn at approximately that rate in comparable groups. OutcomeIn an illustrative deployment, the company uses the model as a decision-support tool. A retention team reviews high-risk cases, records outcomes, and monitors performance across customer segments. The model is retrained only after defining a time-based evaluation protocol and checking whether policies or customer behavior have changed. Learning pointsThe case demonstrates that mathematical foundations support the entire workflow: vectors encode customers, matrices organize data, likelihood defines training, gradients enable optimization, and probability supports calibrated decisions. It also shows that model quality includes data governance, leakage prevention, threshold selection, monitoring, and human accountability. 8. Limitations, Responsible Use, and Best PracticesMathematical models simplify reality. Statistical estimates depend on sampling, measurement quality, and assumptions such as independence or stable data-generating processes. Correlation does not establish causation. A model trained on historical decisions may reproduce institutional bias, especially when labels reflect unequal access or inconsistent human judgments. Practitioners should document feature definitions, data provenance, preprocessing, assumptions, and evaluation populations. Sensitive attributes require careful legal and ethical treatment; excluding an attribute does not guarantee fairness because proxy variables may remain. Privacy risks can arise from collecting, linking, or retaining detailed records. Relevant privacy, anti-discrimination, sectoral, and data-protection requirements must be addressed according to jurisdiction and application. Numerically, standardize when scale differences hinder optimization, protect against overflow in exponentials, use stable solvers, and inspect gradients and losses. Split data before fitting transformations, use validation data for model-selection decisions, reserve the test set for final evaluation, and report uncertainty where possible. A mathematically elegant objective is not automatically the right organizational objective. Contemporary machine-learning systems increasingly use automatic differentiation, vectorized hardware, probabilistic programming, and uncertainty-aware modeling. These tools improve capability but do not eliminate the need to understand assumptions, units, data-generating processes, or consequences of errors. Chapter SummaryVectors and matrices provide the computational language of machine learning: vectors represent observations and parameters, while matrices organize datasets and enable efficient linear operations. Dot products produce linear predictions, norms measure size and distance, and matrix formulations support regression. Functions map inputs to outputs, derivatives measure local change, and gradients identify directions of greatest increase. The chain rule supports differentiation through compositions. Gradient descent minimizes a chosen loss by moving opposite the gradient, although learning rate, curvature, non-convexity, and numerical stability affect its behavior. Descriptive statistics summarize central tendency, spread, association, and outliers. Probability distributions represent uncertainty, while conditional probability distinguishes an event’s overall frequency from its probability under evidence. Bayes’ theorem combines prior prevalence with evidence. Likelihood evaluates parameter compatibility with observed data and leads naturally to log-loss objectives. Finally, machine learning requires more than formulas. Assumptions, data leakage, scaling, calibration, fairness, privacy, monitoring, and decision costs determine whether a mathematically valid model is useful and responsible. Key TermsScalar: A single numerical value. Vector: An ordered collection of numerical components. Matrix: A rectangular array of values. Dot product: The sum of pairwise products of two equal-length vectors. Norm: A measure of vector magnitude. Design matrix: A matrix organizing observations and features for a model. Function: A mapping from inputs to outputs. Derivative: The instantaneous rate of change of a function. Gradient: A vector of partial derivatives. Convex function: A function for which every local minimum is global, under the relevant domain and conditions. Mean: The arithmetic average of observations. Variance: The expected squared deviation from a mean. Correlation: A standardized measure of linear association. Probability density function: A function whose integrated area over an interval gives a continuous probability. Conditional probability: The probability of an event given another event. Bayes’ theorem: A rule relating posterior, likelihood, prior, and evidence. Likelihood: A function measuring data compatibility with parameter values. Loss function: A numerical measure of prediction error. Gradient descent: An iterative optimization method that moves opposite the gradient. Regularization: A penalty or constraint used to control model complexity. Review QuestionsShort Answer Questions1. What are the usual dimensions of a design matrix containing n observations and p features? 2. Why is the negative gradient used in gradient descent? 3. Distinguish a probability distribution from a likelihood function. 4. What does a correlation near zero imply, and what does it not imply? 5. Why should preprocessing parameters be fitted using training data only? Long Answer Questions1. Explain how vectors, matrices, dot products, and intercepts are used in linear regression. 2. Derive the gradient of the squared-error objective \(J(w)=\frac{1}{2n}\|Xw-y\|^2\). 3. Compare mean, median, variance, standard deviation, and interquartile range, including their sensitivity to outliers. 4. Explain Bayes’ theorem and the roles of prior probability, likelihood, evidence, and posterior probability. 5. Describe batch, stochastic, and mini-batch gradient descent and discuss the effect of learning rate. Analytical / Application Questions1. A disease affects 1% of a population. A test has sensitivity 95% and false-positive rate 4%. Calculate the probability that a person with a positive result has the disease. 2. For \(J(w)=\frac12(wx-y)^2\), calculate one gradient-descent update when x = 3, y = 9, w = 0, and learning rate is 0.1. Interpret the result. 3. Design an evaluation plan for the churn case that addresses class imbalance, data leakage, calibration, threshold selection, and fairness across customer groups. Multiple Choice Questions with AnswersQuestion 1A dataset has 400 observations and 8 features, excluding an intercept. What is the dimension of its design matrix? A. 8 × 400 B. 400 × 8 C. 408 × 8 D. 400 × 400 Correct Answer: B. 400 × 8 Question 2For f(w) = 1/2(wx − y)^2, which expression is the derivative with respect to w? A. wx − y B. x C. (wx − y)x D. (wx + y)x Correct Answer: C. (wx − y)x Question 3A screening test has P(F) = 0.02, P(+|F) = 0.90, and P(+|not F) = 0.05. What is approximately P(F|+)? A. 0.018 B. 0.050 C. 0.269 D. 0.900 Correct Answer: C. 0.269 Question 4Which statement about likelihood is correct? A. It is always a probability distribution over parameters. B. It measures how compatible observed data are with parameter values. C. It is the same as the prior probability. D. It must sum to one over all possible parameter values. Correct Answer: B. It measures how compatible observed data are with parameter values. Question 5If a feature has mean 50 and standard deviation 10, what is its z-score when its value is 70? A. −2 B. 0.5 C. 2 D. 7 Correct Answer: C. 2 Question 6What is the main purpose of subtracting the largest logit before applying softmax? A. To change the predicted class B. To make probabilities sum to more than one C. To improve numerical stability without changing probabilities D. To remove the need for normalization Correct Answer: C. To improve numerical stability without changing probabilities Question 7A gradient-descent learning rate that is excessively large may cause training to: A. Guarantee a global minimum B. Oscillate or diverge C. Eliminate all model bias D. Make the gradient identically zero Correct Answer: B. Oscillate or diverge Question 8Which quantity is most resistant to a single extreme outlier? A. Mean B. Range C. Median D. Variance Correct Answer: C. Median Question 9For binary classification, binary cross-entropy is naturally associated with the negative log-likelihood of which model? A. Bernoulli model B. Uniform model C. Poisson model only D. Normal model only Correct Answer: A. Bernoulli model Question 10Why can a highly sensitive fraud detector still have a low positive predictive value? A. The base rate of fraud may be low. B. Sensitivity is always equal to precision. C. Bayes’ theorem applies only to continuous variables. D. False positives are impossible in classification. Correct Answer: A. The base rate of fraud may be low.
|