The goal of this guide is to connect the equations used in Quiz 1 to the calculations you actually perform. It brings together the supplied Machine Learning Foundations and Machine Learning Techniques material, including calculus, linear algebra, projections, regression, PCA, kernels, clustering, maximum likelihood, and EM.
The notebook contains two question sets: ML Techniques Mock Quiz 1 (21 questions) and ML Foundations Mock Quiz 1 (25 questions). They are included with their answers and explanations, but are mock-quiz questions, not independently verified past-year exam questions. The separate practice prompts and recall cards from the original site are omitted, as requested.
1. Machine learning basics
Tasks, data, models, loss functions, and dataset splits.
1.1 ML definition and applications
What machine learning does
Machine learning fits a mathematical model using examples. After training, the model is used on new inputs. For example, a house-price model learns from houses whose prices are known, then estimates the price of another house.
- Data: the examples available for learning.
- Model: a rule that converts an input into a prediction or a probability score.
- Learning algorithm: the procedure that chooses the model’s adjustable values using the data.
- Generalization: how well the fitted model works on unseen examples. Memorizing the training examples is insufficient.
When ML is useful
Use ML when useful example data exist but the input-output rule is difficult to program explicitly. Face detection, spam filtering, and rainfall prediction are examples. Password verification already has an exact rule, so ordinary programming is sufficient.
Two kinds of model
A predictive model estimates a target, such as house price. A probabilistic model describes how likely different observations are, such as the distribution of heights. Linear algebra represents relationships in data; probability describes uncertainty; optimization chooses the fitted parameters.
Source IDs: S08, S09, S10, S11, S12, S13, S36.
1.2 Data and notation
1. Start with a data table
A sample is one observed example: one house, person, image, or coin toss. A feature is one measured property used to describe that example. For house-price prediction, rooms, area, and distance to the metro are three input features. Price is the target: the value to predict.
The housing table in the slides contains six houses. Its metadata specifies units: area in hundreds of square feet, distance in kilometres, and price in units of ten lakh rupees. Thus an area entry of 9 means 900 square feet.
2. What x, i, j, n, and d mean
We use the letter x for the input measurements. A subscript i identifies which sample we mean. It is a counting label, not multiplication. The letter n is the total number of samples; d is the number of input features in each sample.
The expression “” says that sample i is represented by d real numbers. Here we treat as a column vector: d rows and one column. A scalar is a single number; a vector is an ordered list of numbers; a matrix is a rectangular arrangement of numbers.
Read house 2
The three entries of mean 2 rooms, 700 square feet, and 2.1 km from the metro. The separate scalar is its known price. The notation means feature 3 of sample 2; it does not mean sample 23.
Slide notation: some slides write the i-th sample as , and its j-th feature as . These correspond to and here. In that slide convention, the superscript i is a sample label, not an exponent. A genuine square is written .
3. Row vectors, transpose, and the full dataset
The superscript T means transpose: exchange rows and columns. Thus is a 1×3 row vector. The table displays a sample across a row, even though we define its individual vector as a column. There is no contradiction: the row is the transpose of that column vector.
This is the regression design matrix: one row per sample and one column per feature. For this dataset A is 6×3. In PCA, the source uses a different arrangement: centered sample vectors are stacked as columns in a d×n matrix X. Read the stated convention before multiplying matrices.
4. Features versus parameters
Features are the observed inputs. Parameters are the model’s adjustable values, chosen during training. In a linear prediction, w is a d×1 column vector of weights, one per input feature, and b is a scalar intercept:
The sum symbol means add the indicated terms as j runs from 1 to d. The product is a dot product: multiply corresponding entries and add. Its shape is (1×d)(d×1), so its result is one number.
Example of a prediction, using illustrative weights
The prediction 3.4 differs from the observed target 3.2. Training adjusts the parameters to reduce such errors. These weights illustrate the arithmetic; they are not claimed to be the fitted model.
5. Other notation used in the notes
| Notation | Meaning and example |
|---|---|
| Euclidean length of vector v. For v=(3,4)ᵀ, length = √(9+16)=5. | |
| Indicator of statement B: 1 if true, 0 if false. For example, 1[2 is even]=1. | |
| The smallest loss value. | |
| The parameter value giving the smallest loss. If L(θ)=(θ−2)², its minimum value is 0 and its argmin is θ=2. |
6. Matrix operations used later
To multiply a matrix by a column vector, take the dot product of each matrix row with that column. The inner dimensions must match:
A 2×2 matrix times a 2×1 column gives a 2×1 column. Matrix order matters: AB and BA need not have the same values, and one may be undefined. The identity matrix I has ones on the diagonal and zeros elsewhere; Iv=v. The inverse A⁻¹, when it exists for a square A, reverses A’s transformation: A⁻¹A=AA⁻¹=I. A matrix without an inverse is called singular.
Source IDs: S08, S09, S10, S11, S12, S13, S36.
1.3 ML tasks and loss functions
Supervised versus unsupervised learning
In supervised learning, each sample has both inputs and a known target . The model learns a mapping from inputs to targets. In unsupervised learning, only the input samples are supplied; the aim is to describe, compress, or group them.
| Task | What is learned | Example |
|---|---|---|
| Regression | A numerical target | Predict house price |
| Classification | A category or class label | Predict spam/non-spam |
| Dimensionality reduction | A smaller representation of each sample | Represent many gene measurements with fewer coordinates |
| Clustering | Groups of similar samples | Group photographs without supplied labels |
| Density estimation | A probability model for observations | Describe likely observations from a random source |
Loss measures how wrong a model is
A loss is a number used to score errors. In the following expressions n is the sample count, i selects one sample, f is the model, and f(xᵢ) is its output. Averaging means adding the errors across samples and dividing by n.
Regression: yᵢ is a real-valued target. Squared loss penalizes large prediction errors more strongly:
Example: squared loss
True values (2,5), predictions (3,3): errors are 1 and −2; squared errors are 1 and 4. Average loss = (1+4)/2 = 2.5.
Binary classification: encode the two classes as −1 and +1. The indicator counts incorrect labels:
Two wrong predictions among ten give loss 0.2 (20% error). A linear classifier uses : a positive score gives +1, and a negative score gives −1. Its decision boundary is . Define a tie rule at zero.
Dimensionality reduction: an encoder f converts a d-feature vector into k coordinates, where k is smaller than d. A decoder g maps those coordinates back to d dimensions. The reconstruction g(f(xᵢ)) should be close to xᵢ:
The arrow describes input and output dimensions. The norm measures the length of the reconstruction-error vector. Clustering minimizes distances to group representatives; density estimation minimizes negative log-likelihood. Their objectives are derived in later chapters.
Other tasks named in the introduction
Multiclass classification chooses among more than two classes. Ordinal classification uses ordered categories, such as ratings. Ranking orders items. Link prediction predicts connections, such as friend suggestions. Online learning updates as data arrive; bandits and reinforcement learning concern sequential decisions. The introduction names these tasks; their detailed algorithms are outside the supplied portions.
Source IDs: S08, S09, S10, S11, S12, S13, S36.
1.4 Dataset splits and probability models
Training, validation, and test sets
Split the available labeled samples according to their role:
- Training set: used to fit the model parameters, such as w and b.
- Validation set: used to choose settings such as polynomial degree or regularization strength. Compare candidate models here.
- Test set: used to evaluate the selected model on unseen data. Do not use it to make model-selection decisions.
A low training loss can come from memorization. A separate test set measures whether the learned relationship generalizes. For example, fit degree-1 and degree-5 polynomials on the training data, choose their degree using validation errors, then report the chosen model’s test error.
Probability versus density
For a discrete random variable, p(x) is the probability of outcome x. Its probabilities add to one. For a continuous random variable, p(x) is a density; probabilities correspond to areas under the density curve:
The symbol ∫ denotes integration, which adds the area over a continuous range. For continuous X, the probability of one exact value is zero; the density there can still be positive. A density value is not itself a probability.
Uniform-density example
A uniform model on [0,2] has constant density 1/2 inside that interval and zero outside. Probability of the interval [0,1] = width 1 × density 1/2 = 1/2. An observation outside [0,2] has zero density under this model.
Density-estimation objective
We want a normalized model that assigns high probability or density to observed data. A larger p(xᵢ) gives a smaller negative log term:
The logarithm is increasing, so minimizing this loss is equivalent to maximizing log-likelihood. If an observation has zero model probability/density, its log term is −∞ and the negative log-loss is +∞.
Source IDs: S08, S09, S10, S11, S12, S13, S36.
2. Calculus
Continuity, derivatives, Taylor approximation, gradients, and Hessians.
2.1 Sets, logic, and functions
Sets, statements, and functions
A set is a collection of objects. The notation says that x is an element of set A; says every element of A is also in B. The union contains elements in either set, the intersection contains elements in both, and the complement contains elements in the stated universe that are not in A.
In logic, means “for every” and means “there is at least one.” The implication says that whenever P is true, Q is true. The equivalence means each statement implies the other. Complements reverse union and intersection (De Morgan’s laws):
Example: apply a complement rule.
Suppose the universe is , , and . Then , so . Also , , and their intersection is , as the identity predicts.
Number spaces, distance, and functions
denotes the integers, the real numbers, and the set of real vectors with d coordinates. A point has Euclidean length ; the distance between x and y is . An epsilon-ball around a is the set of points whose distance from a is less than , where is a chosen radius. A vector subspace must contain zero and remain closed under addition and scalar multiplication.
A function assigns each input in domain A exactly one output in codomain B. Its graph is . For a scalar function of two variables, a contour connects inputs with the same output value; a heat map uses color to show those values.
Example: subspace or shifted plane?
The plane contains and is a subspace: sums and scalar multiples of vectors satisfying the equation still satisfy it. The plane does not contain zero, so it is an affine hyperplane, not a vector subspace.
Source IDs: S14, S15, S16, S17, S18, S19, S20.
2.2 Sequences, continuity, and differentiability
What convergence says
A sequence is a list of values indexed by positive integers n. It converges to a if its terms eventually get as close to a as any positive tolerance allows. Here is an arbitrary distance tolerance, N is an index that may depend on that tolerance, and “for all ” means every later term stays within the tolerance.
This order of quantifiers matters: choose the tolerance first, then find a cutoff N that works for every later term. For example, converges to 0: given any , choose an integer ; then gives .
Continuity and derivatives
A function is continuous at a when inputs near a have outputs near . In one variable this is equivalent to , and also to preserving limits of every sequence approaching a. At a piece boundary, check the left-hand limit, right-hand limit, and the actual value separately.
The derivative measures the limiting slope of secant lines. In the definition, h is a nonzero input change that tends to zero.
Differentiability at a implies continuity there, but continuity need not imply differentiability. For , the left slope at zero is −1 and the right slope is +1, so the function is continuous but has no derivative at zero. A jump discontinuity is not continuous.
Example: check a piecewise join.
Let for , and for . At the join, both one-sided limits and the value equal 1, so f is continuous. The left derivative is 1 and the right derivative is 2, so f is not differentiable there.
Procedure at a piecewise boundary
- Compute the left-hand limit and right-hand limit.
- Compare both limits with the defined value ; all three must agree for continuity.
- For differentiability, compute the left and right difference-quotient limits; both must exist and agree.
Source IDs: S14, S15, S16, S17, S18, S19, S20.
2.3 Linear and Taylor approximations
Replace a curved function locally by a line
Choose a base input a and let h be a small change from a. The tangent-line approximation uses the function value and slope at a:
It is useful when h is small and the function is differentiable near a. The symbol means an estimate, not an identity; accuracy usually worsens as the input moves farther from a.
Add curvature with Taylor terms
If f has enough derivatives near a, include curvature and higher-order shape. The k-th derivative is denoted , and is the factorial (for example, ). The cubic Taylor polynomial is
Each added term records another local feature: value, slope, curvature, then change in curvature. Common expansions about zero are , , , and . For the logarithm and reciprocal, require ; all are local approximations near zero.
Worked example: estimate .
- Set , base point , and change .
- Compute and , hence .
- Use the tangent estimate: .
The exact value is about 7.07107; the small difference is the approximation error.
Source IDs: S14, S15, S16, S17, S18, S19, S20.
2.4 Derivative rules and stationary points
Rules for combining derivatives
For differentiable functions g and h of the same real input x, the product rule accounts for each factor changing, while the chain rule differentiates an outer function after an inner one:
Here and mean derivatives with respect to their input, and means . In the chain rule, evaluate the outer derivative at the inner output, then multiply by the inner derivative.
Worked example: chain rule.
For , the outer function is , the inner function is . Since and , . At , the slope is .
Find and classify candidates
An interior local maximum or minimum of a differentiable function must have zero first derivative. Such a point is called stationary. Zero derivative only identifies a candidate: has derivative zero at zero but keeps increasing through zero, so it has no extremum there.
| At a stationary point a | Conclusion |
|---|---|
| Strict local minimum (curve bends upward) | |
| Strict local maximum (curve bends downward) | |
| Inconclusive; inspect higher derivatives or nearby function values |
To find a global optimum on a closed interval, also check the endpoints. If a function is not differentiable at a point, that point can still be an extremum and must be checked separately.
Worked example: minimum of a quadratic.
For , ; setting it to zero gives . Since , this is a strict local minimum, with value . On any interval containing 2, compare this value with any endpoint values to decide a global minimum.
Source IDs: S14, S15, S16, S17, S18, S19, S20.
2.5 Hyperplanes, partial derivatives, and gradients
Lines, planes, and hyperplanes
In , a line through point in direction vector is , where t is any real number. To write the line through distinct points a and b, take . A hyperplane is the set of points satisfying , where is a normal vector perpendicular to the plane, b is a scalar offset, and . It has dimension . The transpose symbol T turns a column vector into a row, so is the dot product.
Example: interpret a plane equation.
In , has normal . It is a two-dimensional plane, and the right side 4 shifts it away from the origin; since it does not contain zero, it is not a vector subspace.
Partial derivatives and gradient
Let be a scalar-valued function and let a be an input vector. The vector has a 1 in coordinate j and zeros elsewhere. A partial derivative changes coordinate j while holding every other coordinate fixed. Here h is a small scalar change:
The gradient is a column vector of all first partial derivatives. If f is differentiable, its local linear approximation is
where h is now a d-dimensional displacement vector (not the scalar from the limit above), and the transpose makes the dot product a scalar.
Worked example: tangent plane estimate.
For , . The partial derivatives are and , so . For displacement , the linear estimate is ; thus (the actual value is about 0.98542).
Condition: the displayed gradient approximation follows from differentiability. Having all partial derivatives at a point alone does not guarantee a valid linear approximation.
Source IDs: S14, S15, S16, S17, S18, S19, S20.
2.6 Directional derivatives and Hessian
Directional rate of change
For a differentiable scalar function , input point a, and unit direction vector u (so ), the directional derivative is the rate of change per unit distance:
The dot product selects the component of the gradient along the direction. The Cauchy-Schwarz inequality says this component cannot exceed the gradient length when u is a unit vector. Therefore, when , steepest ascent is along , at rate ; steepest descent is the opposite direction. Any unit u with decreases f locally. The gradient is perpendicular to a smooth level contour through a, because movement along that contour has zero first-order change.
Worked example: compute a directional rate.
- Let and . Its gradient is , so .
- The direction is unit length, because .
- Thus : f increases at rate 2.6 per unit distance in that direction.
- If the requested direction is , first normalize it to ; its rate is then .
Hessian and local shape
The Hessian is the d-by-d matrix of second partial derivatives; its entry in row i, column j is at a. For a small displacement h, the second-order approximation adds curvature:
At a stationary point the gradient term vanishes. Positive definite H (positive quadratic curvature in every nonzero direction) gives a strict local minimum; negative definite gives a strict local maximum; indefinite curvature gives a saddle. A semidefinite Hessian may be inconclusive. For two variables, define , using second partials at the candidate: if and , it is a minimum; if and , a maximum; if , a saddle. If D=0 this test gives no conclusion.
Worked example: classify a stationary point.
For , the gradient vanishes at . The Hessian is , which is positive definite; hence the origin is a strict local minimum (indeed, the global minimum).
Source IDs: S14, S15, S16, S17, S18, S19, S20.
3. Four fundamental subspaces
Column, row, null, and left null spaces; rank; linear systems.
3.1 Subspaces and dimensions
Span, independence, basis, and dimension
A linear combination of vectors means multiplying them by scalar weights and adding: c₁v₁+c₂v₂. Their span is the set of all combinations obtainable by varying the weights. Vectors are linearly independent if the only weights producing the zero vector are all zero; otherwise one vector adds no new independent direction. A basis is an independent list spanning a space. The dimension is its number of basis vectors. For example, (1,0)ᵀ and (0,1)ᵀ form a basis of ℝ²: a(1,0)ᵀ+b(0,1)ᵀ=(a,b)ᵀ.
The four spaces associated with a matrix
Let be an -row, n-column real matrix, written ; let r be its rank, the number of pivot columns after row reduction. Each space collects vectors related to multiplication by A:
| Space | What it contains | Ambient space | Dimension |
|---|---|---|---|
| Column space | All linear combinations of A’s columns, equivalently all outputs | r | |
| Row space | All linear combinations of A’s rows | r | |
| Null space | Inputs x satisfying | n−r | |
| Left null space | Vectors y satisfying | m−r |
For a subspace U, means all vectors perpendicular to every vector in U. The fundamental orthogonality relationships and rank-nullity theorem are
The null space is a subspace because if Au=Av=0, then for any scalars , . Also every row of A has zero dot product with any x in N(A), which explains why the row space is perpendicular to the null space.
Worked dimension example.
If A has 5 rows, 8 columns, and rank 3, then its column and row spaces each have dimension 3. There are free dimensions in the null space and in the left null space. Check the pairs add to their ambient dimensions: and .
Source IDs: S21, S22, S26, S27.
3.2 Bases using row reduction
Allowed row operations
Row reduction uses three operations that preserve solutions of a system: swap two rows; multiply a row by a nonzero scalar; add a multiple of another row. For example, subtracting twice row 1 from row 2 changes (1,2) and (2,5) into (1,2) and (0,1). Continue eliminating entries to expose independent equations. In echelon form, each successive pivot lies farther right; RREF additionally makes each pivot 1 and the only nonzero entry in its column. A variable in a nonpivot column is free.
Use row reduction to find bases
A basis is a linearly independent list that spans the whole space. Row operations simplify equations, but which basis can be read from the reduced matrix depends on the space being found.
- Reduce A to echelon form or reduced row echelon form (RREF). Each leading entry is a pivot; the number of pivots is the rank r.
- Column space: identify pivot-column indices in the reduced matrix, then take those columns from the original A. Row operations can change the column vectors and the column space itself.
- Row space: the nonzero rows of an echelon form are a basis. Row operations preserve the row space.
- Null space: solve the reduced homogeneous system. Express pivot variables in terms of free variables, then set each free variable to 1 in turn and the others to 0 to get basis vectors.
- Left null space: solve , where y has one coordinate per row of A.
Worked example: null-space basis (S21, pp. 5-8).
For the 3-by-4 matrix below, the displayed U is obtained by row operations. The pivot columns are 1 and 3; the free variables are .
To solve , solve the equivalent equations : , so ; and , so . Therefore
There are two independent basis vectors, matching nullity . The left null space is , since the third row of A is the sum of its first two rows.
Common mistake: do not report pivot columns of U as a column-space basis for A. Use those column indices to select the original columns.
Source IDs: S21, S22, S26, S27.
3.3 Existence and uniqueness of solutions
When does have a solution?
Let A be an matrix, x an unknown vector in , and b a target vector in . Multiplication forms a linear combination of A’s columns, with the entries of x as its coefficients. Thus a solution exists exactly when b lies in the column space , equivalently when adding b as a column does not increase rank:
In row reduction of the augmented matrix , a row of the form with means the impossible equation , so the system is inconsistent.
How many solutions?
If is one particular solution, every solution is obtained by adding a null-space vector:
This works because . Therefore a consistent system has a unique solution precisely when , equivalently A has full column rank n. If the null space contains a nonzero vector, adding any scalar multiple of it gives another solution, so there are infinitely many. A square invertible A has full column rank and the unique solution . For a rectangular matrix, “not invertible” alone does not determine whether its null space is nonzero.
Worked example: a consistent system with infinitely many solutions.
Take and . The second equation is three times the first, so there is one independent equation . Let the free variable . Then , giving . The vector spans N(A), and the infinitely many solutions are one particular solution plus that null-space direction.
Shape check: full column rank means rank(A)=n and guarantees uniqueness when the system is consistent; for a tall matrix it may not cover every b. Full row rank means rank(A)=m and guarantees a solution for every b; if n>m, free variables can still make the solution non-unique.
Conditions and a contrast
Full column rank guarantees uniqueness if a solution exists, but does not guarantee a solution for every b when the matrix is tall. Full row rank guarantees a solution for every b; if there are extra columns, those solutions may not be unique. For the example above, solvability requires b to lie on the line spanned by , because the column space has dimension 1.
Source IDs: S21, S22, S26, S27.
4. Projection and least squares
Orthogonality, projections, normal equations, and line fitting.
4.1 Orthogonality and line projection
Vectors and perpendicularity. A vector is a list of coordinates; we write it as a column. For example, has two entries and is a vector. The superscript means transpose: it turns a column into a row. The dot product multiplies matching entries and adds them; it is zero exactly when the vectors are perpendicular (orthogonal). A vector has length . Orthogonal vectors of length one are orthonormal. Nonzero mutually orthogonal vectors are linearly independent. Two subspaces are orthogonal if every vector in one is perpendicular to every vector in the other.
Projecting onto a line. Let be a direction vector and let be the vector we want to approximate. The line consists of all multiples of . Its closest point to has form , where the scalar is chosen so the error is perpendicular to the line direction. Thus , giving:
Here each have shape for some dimension ; and are scalars. Scaling by any nonzero number changes its length but not the line or its projection. Since , Pythagoras gives : the projection is the closest point on the line.
Tutorial 3.3 · projection in four dimensions
For , , both are . Compute and . Thus , and multiplying every coordinate gives . Subtraction gives residual ; check .
Source IDs: S22, S23, S24, S25, S28.
4.2 Least squares and normal equations
What least squares solves. Suppose is an matrix (m rows, n columns), is an unknown coefficient column of shape , and is an observed column of shape . Then is an prediction. Often no choice of makes exactly, so choose to minimize the squared length of the residual :
The fitted vector lies in the column space , the set of all linear combinations of A’s columns. At the closest point, the residual is perpendicular to every column of A and hence to every vector in . This is , or . Substituting yields the normal equations:
Dimensions help check the equation: is , so both sides are . Equivalently minimize . Differentiating gives , and setting this gradient to zero gives the same equations. The factor cancels the 2 from differentiating a square.
The normal equations always have at least one solution, even when A’s columns are dependent. If rank deficient, several coefficient columns can describe the same best fit, but the fitted vector p and residual e are still unique. Full column rank makes invertible: for any nonzero , , because independent columns ensure .
Source IDs: S22, S23, S24, S25, S28.
4.3 Projection matrices and line-fitting example
Projection matrix. When is with independent columns, it has a unique least-squares coefficient vector for each observation . Applying the formula for to get the fitted vector gives:
Here is an matrix acting on an observation. It satisfies (symmetric) and (projecting twice changes nothing). For an orthonormal column basis Q, , so the formula simplifies to . The identity matrix I has ones on its diagonal and zeros elsewhere; multiplying by I leaves a vector unchanged. A symmetric, idempotent matrix is an orthogonal projection. P fixes vectors in , sends vectors in to zero, and projects onto the perpendicular complement.
Example · S25
Fit a line to points . We seek slope m and intercept c. Let denote each input coordinate (to distinguish it from the coefficient vector). For a line, each predicted value is . Stacking the three equations makes a matrix (one row per point and one column per coefficient), a coefficient vector, and b the observed outputs:
Multiply row by column to build the normal equations: , and . Solve to get . So the fitted line is .
Check the perpendicularity: . The minimum squared vertical error is . This fit minimizes vertical prediction errors (differences in y), not perpendicular distances in the original x-y plot.
Source IDs: S22, S23, S24, S25, S28.
5. Linear, polynomial, and ridge regression
Design matrices, Gaussian noise, polynomial features, and regularization.
5.1 Linear regression
Inputs, features, and coefficients. A training set has n observations. Observation i has feature column (d measured inputs) and scalar target . The index i labels which observation is meant; it runs from 1 to n. A coefficient column assigns a weight to each feature. The dot product is a weighted sum and predicts observation i: . To include an intercept, append a constant 1 to every feature vector and give it its own coefficient.
Put each feature row into a design matrix A. Then A has shape (or when an intercept column is included); the coefficient vector has the matching number of entries, and the target column has shape . Thus is the column of all predictions. The residual stores prediction minus observation for each row.
This is linear regression because predictions are linear in the unknown coefficients, even if we later transform the inputs. The gradient points in the direction of increasing loss; at a least-squares minimum it is zero:
Here H is the Hessian (matrix of second derivatives), of size d-by-d, or the number-of-coefficients squared. It is positive semidefinite, so the loss is a convex bowl; if columns of A are independent it has a unique minimum. Multiplying the unregularized loss by a positive constant changes its scale, not its minimizer.
Why Gaussian noise gives squared error. Suppose each observed target is a prediction plus random noise: , where the errors are independent normal random variables with mean zero and variance . Their joint likelihood, written p(y|A,θ), is a product of Gaussian densities. It is distinct from the squared-error loss L(θ). Taking its logarithm turns that product into a sum; terms depending on are minus the sum of squared residuals divided by . Therefore maximizing likelihood over gives exactly the least-squares solution:
Source IDs: S10, S25, S29, S34.
5.2 Polynomial regression
Polynomial features. A single scalar input x can be turned into several features: for degree q, use , a feature column. Its entries are the constant, input, input squared, and so on. A matching coefficient column is ; the prediction is the dot product . Though the curve can bend as x changes, the formula is still linear in the unknown coefficients.
For n observations, put in row i of A and put observed values in y. Then A is , is , and y is ; solve the same least-squares normal equations. For inputs −1, 0, 2 and degree 2, each row lists :
There are q+1 coefficients including the intercept. Raising q adds flexibility but can make the fitted curve chase noise; choose degree using data held out for validation.
Exact quadratic fit · S34
For observations (1,3), (2,1.5), (3,2.5), seek three coefficients for a degree 2 polynomial. Each row is , so the design system is:
Solving gives , hence . Substitute x=1, 2, and 3 to check predictions 3, 1.5, and 2.5, respectively.
Source IDs: S10, S25, S29, S34.
5.3 Ridge regression
Ridge regression shrinks coefficients. When features overlap strongly or there are more coefficients than independent observations, least squares can be unstable or non-unique. Ridge adds a penalty for large coefficients. Let A be the design matrix, the coefficient column and y the observations. The identity matrix I is ; controls penalty strength:
Differentiate both terms: the loss contributes , while the penalty contributes . Setting their sum to zero gives the displayed equation. The added diagonal term penalizes coefficients and stabilizes the solve. For any nonzero coefficient vector v, , so the matrix is positive definite and the solution unique, even if A’s columns are dependent. Small λ gives weak shrinkage and greater overfitting risk; large λ gives stronger shrinkage and greater underfitting risk.
Conditions
Factor clarification · S29, p. 7. If the penalty is written as without a factor of 1/2, its derivative is , so the normal equations contain . The objective here uses . It penalizes every coefficient, including an included intercept.
Source IDs: S10, S25, S29, S34.
6. Eigenvalues and diagonalization
Eigenvectors, diagonalization, matrix powers, and Fibonacci recurrence.
6.1 Eigenvalues and eigenvectors
Determinant used in the eigenvalue calculation
For a 2×2 matrix, the determinant is the product of the main diagonal entries minus the product of the other diagonal:
A square matrix is singular exactly when its determinant is zero. The characteristic equation below applies this test to A−λI, so a nonzero eigenvector can solve (A−λI)v=0.
Meaning. A square matrix A transforms n-dimensional columns into n-dimensional columns. Most vectors change direction when transformed. An eigenvector is a nonzero column v whose direction is preserved (or reversed) by A; its eigenvalue λ tells the scale:
Here v is , λ is a scalar, and both sides are . If λ is positive the direction stays oriented; if negative it reverses; if zero the vector is sent to zero. The zero vector is excluded because every matrix sends it to zero, which would make the definition meaningless.
Rearrange to , where I is the identity. For this system to have a nonzero solution, must be singular, so its determinant is zero. This gives a practical procedure:
- Find roots λ of the characteristic equation .
- For each root, solve ; any nonzero solution is an eigenvector.
- Check by multiplying A v and checking it equals λv. As quick checks including repeated roots, eigenvalues sum to trace (diagonal sum) and multiply to determinant.
Example · multiply to check
The roots are 4 and 2. For λ=4, choose : . For λ=2, : . Adding cI keeps eigenvectors and adds c to each eigenvalue. General real matrices can have complex eigenvalues; for example, a 90° rotation has eigenvalues ±i. Eigenvalues of A+B generally cannot be found by simply adding those of A and B.
Source IDs: S30, S31, S32, S33, S35.
6.2 Diagonalization and matrix powers
Diagonalization changes to an eigenvector coordinate system. An matrix A is diagonalizable (over the chosen number system) if it has n independent eigenvectors. Make S the matrix whose columns are those eigenvectors, and make Λ the diagonal matrix of matching eigenvalues in the same column order. The relation is:
S is invertible because its columns are independent. In coordinates along eigenvectors, applying A only scales each coordinate by its eigenvalue; Λ expresses this simple scaling. Consequently powers are easy:
To compute , first change the starting vector into eigenvector coordinates with , raise each diagonal entry of Λ to kth power, then change back with S. Distinct eigenvalues have independent eigenvectors, so n distinct eigenvalues guarantee diagonalizability. A repeated eigenvalue may or may not provide enough independent eigenvectors. S is not unique: eigenvectors can be rescaled, or columns reordered if matching entries of Λ are reordered too.
Why distinct eigenvalues give independent eigenvectors
For two vectors with distinct eigenvalues, suppose . Apply A and subtract times the original relation: . Since the eigenvalues differ and , , then . The same argument extends to any finite set of distinct eigenvalues.
Example · S31
The first column checks as ; the second as . Thus , with matching eigenvectors and eigenvalues. By contrast, has only one independent eigenvector, so a 2-by-2 S cannot be formed and it is not diagonalizable.
Source IDs: S30, S31, S32, S33, S35.
6.3 Symmetric matrices and orthogonal diagonalization
Symmetric matrices have an orthonormal eigenbasis. If a real matrix A equals its transpose (), the spectral theorem says all eigenvalues are real and we can choose mutually perpendicular eigenvectors of length one. Put them in the columns of Q and their eigenvalues in diagonal Λ:
Because the columns of Q are orthonormal, transforming coordinates back uses transpose instead of a general inverse. Eigenvectors with distinct eigenvalues are perpendicular; for a repeated eigenvalue, choose an orthonormal basis within its eigenspace. A real matrix is orthogonally diagonalizable exactly when it is symmetric.
A symmetric matrix is positive semidefinite (PSD) if for every vector v. For a symmetric matrix this is equivalent to all eigenvalues being nonnegative. Covariance matrices and valid kernel Gram matrices are PSD.
Conditions
Orthogonality clarification · S33, p. 1. For symmetric A, eigenvectors associated with distinct eigenvalues are orthogonal.
Source IDs: S30, S31, S32, S33, S35.
6.4 Differential systems and Fibonacci recurrence
Continuous system. In the differential equation , u(t) is an n-entry state column that changes over time and A is an matrix. If , then is a solution: differentiating multiplies v by λ, and applying A does the same. When A is diagonalizable, combine these eigenvector solutions to match the initial state. A real mode decays for λ<0, stays constant for λ=0 and grows for λ>0.
Discrete recurrence and Fibonacci. For repeated updates , the index k counts steps and the starting column is . Repeated multiplication gives . Fibonacci numbers start and satisfy . Package two consecutive values in a column so one matrix update performs the recurrence:
The matrix A has eigenvalues and corresponding eigenvectors . The initial state equals . Applying A k times scales these two eigenvectors by and , so the second component is:
Since , its powers shrink to zero. For large k, . The same diagonalization shortcut applies to any recurrence representable as a fixed matrix update.
Source IDs: S30, S31, S32, S33, S35.
7. Principal component analysis (PCA)
Centering, reconstruction error, explained variance, and dual PCA.
7.1 Centering, encoding, and reconstruction
Center the samples
PCA represents each sample using fewer coordinates while keeping reconstruction error small. Let n be the sample count and d the number of features. Each original sample xᵢ is a d×1 column vector. The mean vector μ contains the average of each feature. Subtract it from every sample:
The tilde marks a centered sample. In this PCA matrix X, samples are columns and features are rows. Centering moves the mean to the origin; it does not change the relative positions of samples.
Covariance records variation
A feature’s variance is its average squared deviation from its mean. A covariance is the average product of deviations of two features: positive means they tend to move together, negative means they tend to move oppositely. Put these values in a d×d covariance matrix C:
Here a and b index features; i indexes samples; (x̃ᵢ)ₐ is coordinate a of sample i. Diagonal entries are variances. The source uses 1/n throughout; some statistics texts use 1/(n−1).
Encode and reconstruct along one direction
Choose a d×1 unit vector w. The dot product gives the signed coordinate zᵢ along that direction. The reconstructed sample x̂ᵢ is the mean plus that coordinate times the direction:
This stores one number per sample instead of d. A hat marks a reconstruction here, and the residual xᵢ−x̂ᵢ is the lost information. PCA chooses the direction that makes these residuals small.
Use k directions
Put k orthonormal direction vectors into the columns of a d×k matrix W. “Orthonormal” means mutually perpendicular, each of length one; consequently WᵀW=Iₖ. The code zᵢ now has k entries:
Shape check: (k×d)(d×1) gives a k×1 code; (d×k)(k×1) gives a d×1 reconstruction. Storage is nk values for codes, dk for W, and d for μ, compared with nd original values. Keeping a complete basis reconstructs exactly but does not compress.
Example: follow a sample through PCA
For x₁=(1,2)ᵀ and x₂=(3,4)ᵀ, the mean is μ=(2,3)ᵀ. The centered columns are (−1,−1)ᵀ and (1,1)ᵀ. Both features have variance 1 and their covariance is 1, so C has all four entries equal to 1.
Choose w=(1,1)ᵀ/√2. Sample 2’s code is z₂=wᵀ(1,1)ᵀ=√2. Reconstruction gives μ+z₂w=(2,3)ᵀ+(1,1)ᵀ=(3,4)ᵀ. One coordinate suffices here because both samples lie on the same line through their mean.
Source IDs: S01, S02, S12.
7.2 PCA objective and derivation
PCA chooses a -dimensional linear subspace that makes the average squared reconstruction residual small. First consider one unit vector . The projection is . The Pythagorean theorem splits the centered point into its projection and an orthogonal residual:
The left side does not depend on . Therefore, minimizing the sum of squared residual lengths is equivalent to maximizing the average squared projection coordinate. Because the centered coordinates have mean zero, this average squared coordinate is their variance.
The equality follows by expanding the scalar: , and summing gives . The Rayleigh quotient theorem says the maximum over unit is the largest eigenvalue of ; a maximizing is its eigenvector. For component , maximize while requiring ; then repeat with orthogonality to every earlier component. Since is symmetric positive semidefinite, its eigenvectors can be chosen orthonormal and eigenvalues are nonnegative.
Projected coordinates along different PCA directions have zero covariance (they are uncorrelated). This does not generally mean they are statistically independent; independence requires stronger distributional assumptions.
Why the largest eigenvalue? Express a unit direction w as a combination of C’s orthonormal eigenvectors vⱼ: , where . Then , a weighted average of eigenvalues with nonnegative weights summing to 1. It cannot exceed the largest eigenvalue; choosing its eigenvector attains that maximum.
Source IDs: S01, S02, S12.
7.3 PCA algorithm and component selection
Procedure. For observations , compute and centered columns , form , and find its orthonormal eigenvectors ordered by eigenvalues . Put the first eigenvectors in . Encode each sample with , then decode with . These formulas also specify precisely where centering and adding the mean back occur.
The average squared reconstruction error per observation is the sum of omitted eigenvalues. The fraction of total variance retained is the cumulative eigenvalue sum divided by the full sum:
Choose to meet a target such as 95% retained variance, or select a value that balances storage and reconstruction quality. If all eigenvalues are zero, every centered observation is zero; the ratio is undefined, but the mean reconstructs every sample exactly. If an eigenvalue is repeated, its individual eigenvectors are not unique: any orthonormal basis for that eigenspace is valid.
Numerical eigenvalue example.
Suppose , so total variance is . One component retains ; two retain ; all three retain . A threshold therefore requires . With , the omitted eigenvalue is , so average squared reconstruction error is under the convention.
An equivalent way to understand the sequence is deflation: subtract each selected projection from every sample residual. After removing the first direction, residuals are orthogonal to it; subsequent PCA directions explain the largest remaining variance. After a complete basis, no residual remains. Each selected eigenvalue is the variance captured in its direction and the decrease in average squared error when that component is added.
Source IDs: S01, S02, S12.
7.4 Dual PCA
Use a smaller eigenproblem when d is large
X is the d×n centered-data matrix. Computing all eigenvectors of the d×d covariance C can cost roughly O(d³). When d is much larger than n, instead form the Gram matrix K=XᵀX, which is n×n. Its entry Kᵢⱼ is the dot product of centered samples i and j.
Let βⱼ be a unit eigenvector of K with positive eigenvalue ρⱼ (rho). βⱼ has n entries, one coefficient for each sample; it is not yet a direction in the d-feature space:
Multiply by X to turn those n sample coefficients into a d-dimensional feature vector, then normalize its length:
The normalization works because . The source also writes , giving . The nonzero eigenvalues of XXᵀ and XᵀX agree; the division by n enters only when converting to C=XXᵀ/n.
- Center data, then form K=XᵀX.
- Find the leading positive eigenpairs (ρⱼ,βⱼ) of K, with unit βⱼ.
- Compute wⱼ=Xβⱼ/√ρⱼ.
- Use these feature directions to encode and reconstruct as in ordinary PCA.
Do not divide by a zero eigenvalue: it carries no variance. Centered X has rank at most min(d,n−1), so there are at most n−1 nonzero components. The eigenproblem costs roughly O(n³); forming K costs roughly O(dn²), with additional cost to map directions.
Example: check the normalization
The unit vector β=(−1,1)ᵀ/√2 has eigenvalue ρ=4. Then Xβ=(√2,√2)ᵀ, so w=Xβ/2=(1,1)ᵀ/√2. Its covariance eigenvalue is ρ/n=2. This small example checks the algebra; the computational benefit matters when d≫n.
Source IDs: S01, S02, S12.
8. Kernel PCA
Feature maps, valid kernels, Gram centering, and component coordinates.
8.1 Feature maps and kernels
Why map features? Ordinary PCA finds linear directions in the input coordinates. If the pattern is curved, a linear subspace can miss it. A feature map sends input to a vector in a possibly much larger space . A nonlinear pattern in the original coordinates may become linear in the mapped coordinates. For example, the circle becomes a linear equation in features .
A kernel evaluates the feature-space dot product directly:
It lets us compute similarities without writing down every coordinate of . This matters because may be large or even infinite. Kernel PCA uses these pairwise dot products in place of ordinary dot products.
Polynomial example. For , expands to . Thus one valid map is:
Taking its dot product with reproduces the expansion. The coefficients are needed to match the cross terms.
Common examples are the degree- polynomial kernel for positive integer , and the Gaussian or RBF kernel with . The RBF corresponds to an infinite-dimensional feature space. The kernel trick avoids explicit , but it does not make all computations free: the Gram matrix still stores pairwise training similarities.
Source IDs: S02, S03.
8.2 Kernel validity and centering
For a chosen kernel and observations , define the Gram matrix by . A valid real kernel is symmetric and produces a positive semidefinite Gram matrix for every finite dataset:
Positive semidefinite means all eigenvalues are nonnegative. If one dataset gives a negative eigenvalue (beyond numerical rounding), that disproves validity. A successful check on just one dataset does not prove validity universally. An explicit feature map proves validity because a Gram matrix of dot products has .
PCA requires centered features, so kernel PCA must center the mapped observations, even if raw input coordinates already have mean zero. Let be the all-ones vector and define:
The centered Gram matrix represents centered feature vectors. In entry form, centering subtracts each row and column mean and adds back the grand mean:
has zero row and column means. In general, centering the original values does not center , because nonlinear transformations change feature means.
Example: center a 2×2 Gram matrix
If K is the 2×2 identity, each row and column mean is 1/2 and the grand mean is 1/2. Thus diagonal entries become 1−1/2−1/2+1/2=1/2, and off-diagonal entries become 0−1/2−1/2+1/2=−1/2:
Each centered row now sums to zero.
Source IDs: S02, S03.
8.3 Kernel PCA algorithm
Training coordinates. Build , center it to , and eigendecompose with unit . Keep only positive eigenvalues. Feature covariance eigenvalues are . The corresponding unit principal direction in feature space is , where and is the centered mapped observation. Usually this direction is only conceptual; the algorithm need not form it.
For training observation , its coordinate along component is the inner product . Replacing the inner products by entries of gives . Thus normalization by gives unit directions, while the coordinate has scale . Zero eigenvalues must be discarded because normalization is undefined and those directions contain no variance.
- Evaluate the chosen kernel for every training pair to form .
- Center the Gram matrix using training row means and its grand mean to obtain .
- Find positive eigenpairs of and normalize to length one.
- Set and calculate coordinates from .
- Keep the leading components according to retained variance or another dimension choice.
Kernel PCA produces coordinates in feature space. It does not automatically produce a reconstruction in the original input coordinates; that inverse mapping is a separate problem.
Project a new point using the training centering
For a new , first compute for each training point. Center this vector with the training feature mean, using training Gram sums:
Then its coordinate is . Reusing training means is important: the new point must be expressed relative to the same centered feature coordinates used to fit PCA.
Source IDs: S02, S03.
9. K-means clustering
Lloyd’s algorithm, convergence, Voronoi regions, initialization, and k selection.
9.1 K-means objective and Lloyd’s algorithm
Setup and symbols. The input is points and a chosen number of clusters. Each label says which cluster contains point . Each centroid represents cluster . The within-cluster sum of squared Euclidean distances is
For fixed centroids, the best label for each point is its nearest centroid: . For fixed labels, the best centroid is the mean of points carrying that label. With indicator equal to one when point belongs to cluster and zero otherwise, the update is
The mean minimizes squared distance because differentiating with respect to and setting the gradient to zero gives equal to the sample average. If a cluster has no points, its denominator is zero; implementations reseed that centroid, drop the empty cluster, or use another explicit rule.
- Choose initial centroids (often from observations).
- Assign every point to a nearest centroid.
- Replace each centroid by the mean of its assigned points.
- Repeat assignment and update until labels stop changing or the objective decrease is negligible.
One assignment and update by hand.
Take one-dimensional points and two starting centroids . Squared distances assign 0 and 2 to cluster 1, and 8 and 10 to cluster 2 (ties absent). Before updating, the objective is . Their means become and . After updating, the objective is . In this case another iteration leaves labels and centroids unchanged. Other initial centers can produce different intermediate assignments and local solutions.
Source IDs: S04, S05.
9.2 Convergence and Voronoi regions
Lloyd’s algorithm alternates two exact minimization steps. With centroids fixed, nearest-centroid assignment cannot increase . With labels fixed, replacing each centroid by its cluster mean cannot increase . Therefore each full iteration is nonincreasing in objective:
There are only possible label assignments. With a deterministic tie rule, a consistent empty-cluster rule, and updates that reduce the objective whenever labels change, the algorithm reaches a stable assignment in finitely many steps. The objective can stay equal in a degenerate tie. This argument establishes convergence to a fixed solution, not a global optimum; initialization can lead to different results.
The assignment boundary between centroids and is where squared distances are equal. A point assigned to rather than satisfies:
Expanding both squares cancels , leaving a linear inequality. So each pairwise boundary is a hyperplane, and the region for one centroid is the intersection of its half-spaces against all others: a convex Voronoi cell. This geometry suits compact, roughly spherical clusters; curved or nonconvex groups may be split awkwardly. Kernel k-means and spectral clustering are alternatives when such structure matters.
Source IDs: S04, S05.
9.3 K-means++ and selection of k
Random starting centroids can land close together and miss a group. Running the algorithm from several initializations and keeping the lowest objective is a practical safeguard. K-means++ spreads the initial centers: choose the first observation uniformly; for each next center, select observation with probability proportional to its squared distance from the nearest center already selected.
Points far from existing centers are more likely to seed a new cluster. If every remaining distance is zero, the data already lie at selected centers, so no positive-distance choice remains. The standard k-means++ guarantee is an expected approximation factor for the distortion relative to optimal k-means, over its random initialization.
Choosing is a separate modeling decision. The distortion generally decreases as increases and becomes zero at if every observation receives its own centroid. Common practical tools include using a likelihood model with a complexity penalty. For a specified likelihood model:
Here is the number of fitted free parameters, is the sample count, and is the maximized likelihood. Lower values are preferred within the same candidate-model comparison. These criteria are not direct universal penalties for raw k-means distortion: a probability model and its parameter count must be specified.
Source IDs: S04, S05.
10. MLE and Bayesian estimation
Likelihood, Bernoulli and Gaussian MLE, Beta posterior, and MAP.
10.1 Likelihood and i.i.d. observations
What is being estimated?
Suppose a coin has an unknown head probability. The outcomes are observed data; the probability is an unknown parameter. Estimation chooses parameter values that explain the observations under an assumed probabilistic model.
Write D for the dataset, n for its size, xᵢ for observation i, and θ (theta) for the unknown parameter or collection of parameters. Unlike earlier vector-valued house inputs, a coin observation xᵢ is a scalar: 1 for heads or 0 for tails. A symbol’s shape depends on the stated model.
The i.i.d. assumption
- Independent: knowing other outcomes does not change an outcome’s probability. This lets us multiply probabilities.
- Identically distributed: all observations use the same distribution and parameter. Every toss uses the same head probability.
L is the likelihood. The product symbol ∏ means multiply the n terms. The vertical bar in p(xᵢ|θ) means “given parameter θ.” To evaluate likelihood, keep the observations fixed and try different θ values. It is not a probability distribution over θ and need not sum or integrate to one over θ.
Three fixed coin outcomes: heads, heads, tails
For head probability p, likelihood = p×p×(1−p). At p=0.5 it is 0.125; at p=0.8 it is 0.128. Maximum likelihood searches the allowed parameter values for the largest likelihood.
Why take logarithms?
Log turns products into sums and is strictly increasing, so the maximizing parameter stays the same. A hat on θ means an estimate; ML means maximum likelihood. “argmax” returns the parameter giving the largest value, rather than the largest value itself. With continuous observations, use densities in these likelihood formulas.
Source IDs: S07, S13.
10.2 Bernoulli and Gaussian MLE
Bernoulli model: estimate a coin bias
A Bernoulli random variable has two possible outcomes: x=1 with probability p and x=0 with probability 1−p. Here p is a scalar between 0 and 1. For n observations, let h be the number of heads and t=n−h the number of tails.
If xᵢ=1, the first expression becomes p; if xᵢ=0 it becomes 1−p. Each head therefore contributes one factor p and each tail one factor 1−p.
- For both h>0 and t>0, differentiate the log-likelihood.
- Set the derivative equal to zero and solve.
- Check boundaries when all outcomes are the same.
The second derivative is negative for an interior solution, confirming a maximum. If h=0, the maximum is p=0; if t=0, it is p=1.
Example
Nine heads and three tails give n=12 and . This estimates the head probability; it does not claim that exactly 75% of every future set of tosses must be heads.
Gaussian model: estimate the mean
A Gaussian (normal) model describes a bell-shaped distribution. The scalar μ (mu) is its center, σ (sigma) is its positive standard deviation, and σ² is its variance, measuring squared spread.
Here exp(a) means eᵃ; π in this density is the mathematical constant. For known positive variance, terms independent of μ can be grouped into a constant:
Maximizing this expression means minimizing squared deviations. Differentiating gives , hence:
Example
For observations 2, 4, 6, the estimated mean is (2+4+6)/3=4. If the variance is also fitted, its MLE is the average squared deviation:
The MLE denominator is n. The n−1 denominator belongs to the unbiased sample-variance estimator, a different objective.
Source IDs: S07, S13.
10.3 Beta-Bernoulli posterior and MAP
Prior and posterior
MLE fits parameters using likelihood alone. Bayesian estimation also represents uncertainty about the parameter before seeing the current data. A prior is that initial distribution; the posterior is the distribution after updating with data.
Let θ be the parameter and D the observed dataset. Bayes’ rule combines the likelihood and prior:
- p(θ): prior density over parameter values.
- p(D|θ): likelihood of the observed data at a candidate parameter.
- p(θ|D): posterior density over the parameter after observing D.
- p(D): evidence, a normalizing constant that does not vary with θ.
The shorthand means “proportional to”: the two sides differ by a constant independent of θ.
Beta prior for a Bernoulli probability
A coin probability p lies between 0 and 1. A Beta distribution is a family of possible prior shapes on that interval. Its positive shape parameters α (alpha) and β (beta) describe the prior; they are distinct from p itself.
The symbol ∼ means “is distributed as.” B(α,β) is the constant making the density integrate to one. Beta(1,1) is uniform; increasing both shapes makes the distribution more concentrated. Prior mean is α/(α+β).
Update after h heads and t tails
Multiply the Bernoulli likelihood by the Beta prior, then combine exponents:
This is another Beta density:
A prior is conjugate when this update keeps the same distribution family. Here heads increase the first shape and tails increase the second.
Turn the posterior into a point estimate
E denotes an expected value, or probability-weighted average. MAP means maximum a posteriori: the mode (peak) of the posterior, not its mean. The displayed interior MAP formula requires α+h>1 and β+t>1; otherwise check boundary modes or a nonunique mode.
Example
Prior Beta(2,2), then 3 heads and 1 tail: posterior Beta(5,3). Posterior mean = 5/8 = 0.625; MAP = 4/6 ≈ 0.667; MLE = 3/4 = 0.75. They differ because they summarize the information differently.
Source IDs: S07, S13.
10.4 MLE, MAP, and posterior mean
| Method | What it uses | Result |
|---|---|---|
| MLE | Likelihood only | Parameter maximizing observed-data likelihood |
| MAP | Likelihood × prior | Mode of posterior |
| Posterior mean | Whole posterior | Average parameter under posterior |
| Bayesian posterior | Likelihood, prior, normalization | Distribution describing remaining uncertainty |
MAP maximizes . A uniform prior makes MAP maximizers agree with likelihood maximizers where the prior is constant and nonzero. A fixed Beta prior has less relative influence as n increases.
For the coin, the posterior mean is a weighted average of the prior mean and observed head fraction:
How much does the prior contribute?
In the weighted-mean formula above, α+β is the prior strength and n is the observation count. The two weights sum to 1. With α=β=2 and h=3 out of n=4, prior mean is 0.5 and observed head fraction is 0.75. Their weights are 4/8 each, giving 0.5(0.5)+0.5(0.75)=0.625. For fixed α and β, more data give the observations a larger weight.
What to report: MLE and MAP each return a parameter value. A Bayesian posterior is a whole distribution; it retains uncertainty. A posterior mean is one numerical summary of that distribution.
Source IDs: S07, S13.
11. Gaussian mixture models and EM
Mixture likelihood, Jensen’s inequality, responsibilities, and parameter updates.
11.1 Gaussian mixture model
Why use a mixture?
A single Gaussian has one center and one spread. Data with several separated groups may require several Gaussian components. A mixture adds their densities with nonnegative weights.
The source develops a univariate model: each observation xᵢ is one real number. n is the number of observations; k is the number of Gaussian components; i indexes observations and j indexes components. Each component j has a mean μⱼ, positive variance σⱼ², and weight πⱼ.
| Symbol | Meaning |
|---|---|
| Hidden component that generated observation i | |
| Probability of choosing component j, before seeing an observation | |
| Center and squared spread of Gaussian component j | |
| All fitted mixture weights, means, and variances together |
Generative process
- Choose zᵢ=j with probability πⱼ. The weights satisfy and .
- Given that component, draw .
We observe xᵢ but not zᵢ. This makes z a latent variable. To get the density for x, add the weighted contributions of all possible hidden components:
In πⱼ, π denotes a learned mixture weight; in √(2π), π is the mathematical constant. Subscripts distinguish the two uses.
Example of the mixture sum
At some x, suppose the two component densities are 0.1 and 0.4, with weights 0.25 and 0.75. The total density is 0.25(0.1)+0.75(0.4)=0.325. It is a density value, not a component assignment.
Likelihood and parameter count
The log of the component sum prevents the simple closed-form fit used for a single Gaussian. EM handles this by alternating between estimates of the hidden assignments and parameter updates.
There are k means, k variances, and k−1 independent weights because the weights sum to 1: 3k−1 free parameters.
Source IDs: S06, S07, S05.
11.2 Jensen’s inequality and EM lower bound
Convexity, concavity, and Jensen’s inequality
A convex function lies below the straight chord joining two graph points; for a concave function the inequality reverses. Let qⱼ be nonnegative weights that sum to 1, and aⱼ be values in the function’s domain:
For concave f, replace ≤ by ≥. The logarithm is concave because its second derivative is negative on positive inputs.
For the mixture, write positive component contributions as aⱼ. Introduce weights qⱼ and apply Jensen to aⱼ/qⱼ:
The right side is a lower bound: it never exceeds the original log-sum. For positive terms, equality holds when all aⱼ/qⱼ are the same, which occurs at .
Apply the bound to every observation
For observation i and component j, choose weights qᵢⱼ with . Use :
F is the bound, depending on both auxiliary weights q and model parameters θ. Zero-weight terms are interpreted by a limit. The auxiliary weights are not the global mixture weights π: there is a separate row of q values for each observation.
Why alternating helps
- Fix θ and choose q to make the bound touch the current likelihood. These q values become the posterior responsibilities.
- Fix q and maximize the bound over θ. The log-sum has become a weighted sum of log terms, so the Gaussian parameters can be updated.
- Repeat. Tightening the bound is the E-step; updating the model is the M-step.
Source IDs: S06, S07, S05.
11.3 E-step and M-step
E-step: estimate the hidden assignments
A responsibility rᵢⱼ is the probability that component j generated observed point xᵢ, using the current model. It is a scalar between 0 and 1. For every fixed observation i, its k responsibilities sum to 1.
The numerator is component j’s weighted density contribution. The denominator adds the contributions of all components for this same point. The index ℓ is a temporary component index in that sum; it plays the same counting role as j.
Example of an E-step
Suppose a point receives weighted contributions 0.02 and 0.08 from two components. Its responsibilities are 0.02/0.10=0.2 and 0.08/0.10=0.8. It belongs partly to both components; EM does not force an immediate hard label.
M-step: fit using fractional memberships
Define Nⱼ as the effective size of component j: add its responsibilities across all n observations. It can be fractional. Use this same E-step responsibility table for all updates below:
- Weight: effective component size divided by total sample count.
- Mean: weighted average of observations.
- Variance: weighted average squared distance from the new mean.
The mixture weights still sum to 1 because the responsibility rows sum to 1. In contrast, the sum of responsibilities down one component’s column is Nⱼ, not generally 1.
Complete M-step example
Observations are x=(0,2). Responsibilities for component 1 are (0.8,0.2), and for component 2 are (0.2,0.8).
- Effective sizes: N₁=N₂=1, so both mixture weights become 1/2.
- Means: μ₁=(0.8×0+0.2×2)/1=0.4; μ₂=(0.2×0+0.8×2)/1=1.6.
- Component 1 variance: 0.8(0−0.4)²+0.2(2−0.4)²=0.64. Component 2 also has variance 0.64.
Only after completing this M-step do we recompute responsibilities from the new model.
Source IDs: S06, S07, S05.
11.4 EM convergence and comparison with k-means
Run EM
- Initialize mixture weights summing to 1, component means, and positive variances.
- E-step: compute responsibilities from the current parameters.
- M-step: update weights, means, and variances using those responsibilities.
- Evaluate log-likelihood and repeat until the increase is small.
Why likelihood does not decrease
The superscript t below counts iterations. qᵗ is the E-step responsibility table computed using θᵗ. The bound touches the likelihood at θᵗ; the M-step improves that bound; the new likelihood is at least as large as the new bound:
Likelihood improvement:
Log-likelihood is nondecreasing. Stop when likelihood improvement or parameter change is small. Result depends on initialization; no global-optimum guarantee.
| k-means | GMM / EM |
|---|---|
| One hard label per point | Soft posterior probabilities |
| Uses nearest centroid | Uses weights, means, and variances |
| Minimizes squared distortion | Maximizes mixture log-likelihood |
| Convex Voronoi cells in input space | Can express unequal spread and curved boundaries |
Conditions
Convergence qualification. Unconstrained GMM likelihood can become unbounded when a variance collapses around one observation. Nondecreasing likelihood alone does not ensure a finite maximum. Practical implementations impose a variance floor and handle components with negligible effective size. The example below uses a variance floor.
Equality is possible at a fixed point. A component with Nⱼ=0 cannot use the displayed mean/variance update because it would divide by zero; reinitialize or remove such a component. Initialization and variance safeguards affect the practical result.
Source IDs: S06, S07, S05.
Quiz 1 source questions: ML Techniques
The following 21 questions are transcribed from the supplied MLT_Mock_Quiz_1.md file embedded in the study site. The original question type, options, and available worked explanations are retained.
ML Techniques Q1
Consider the following kernel:
Which of the following transformation mapping may correspond to the kernel ?
- A.
- B.
- C.
- D.
Answer and worked solution
Answer: D
- Expand the required kernel: .
- Option D has . Its dot product with φ(y) gives exactly those three terms.
- The √2 factor is necessary: multiplying the two middle features produces coefficient 2. The other maps produce different terms.
ML Techniques Q2
A function is defined as
Is a valid kernel?
- A. Yes
- B. No
Answer and worked solution
Answer: B: No
- A real kernel must be symmetric: k(a,b)=k(b,a) for every pair.
- Here , while .
- The asymmetric x₁³x₂ term breaks this requirement; no PSD test is needed after symmetry fails.
ML Techniques Q3
Let be a data matrix of shape for a centered dataset. The first principal component of the dataset is . What will the scalar proxy of the point be on the first principal component?
- A.
- B.
- C.
- D.
Answer and worked solution
Answer: B:
- A scalar proxy is the coordinate along the unit principal direction: z=wᵀx.
- The direction has unit norm since .
- . This is one number, not the reconstructed vector zw.
ML Techniques Q4
Consider the following data set:
For , assume that the following cluster assignment is given to us which shows the clusters assigned to all data points but :
What should be the cluster assigned to the data point ?
- A. 1
- B. 2
- C. 3
Answer and worked solution
Answer: B: Cluster 2
- Use the six already assigned points to compute centroids: cluster 1 contains (0,2),(0,1); cluster 2 contains (2,0),(−2,0); cluster 3 contains (0,−2),(0,−1).
- Their means are (0,1.5), (0,0), and (0,−1.5).
- For x₃=(0,0), squared distances are 2.25, 0, 2.25. The smallest is for cluster 2.
ML Techniques Q5
Consider the scenario where you observe that 8 of your friends {} have scored the following marks in a quiz: {6, 3, −5, −4, 2, −3, 5, −2} respectively.
Which of the cluster initializations given below will result in clusters where your friends with positive marks are in one cluster and the rest are in another after executing one step of the Lloyd’s algorithm?
- A. : No, : No
- B. : Yes, : Yes
- C. : Yes, : No
- D. : No, : Yes
- E. Insufficient Information
Answer and worked solution
Answer: C: I₁: Yes; I₂: No
- The marks sum to 2. Under I₁, μ₁=−2 and . The nearest-center boundary is their midpoint . All negative marks lie left of it and all positive marks right.
- Under I₂, μ₁=6 and . The boundary is .
- The positive mark 2 falls on the same side as the negatives under I₂. One Lloyd step here means compute the means from the initial labels, then reassign.
ML Techniques Q6
Consider the data points shown in the following image:
Consider that in the initialization step of K-means with , the data points and got selected as initial cluster centers. That is, and . As per these cluster centers, the data points were then assigned to either cluster 1 or cluster 2. After this assignment, what will be the value of the objective function ()? Further, as per the assignment of data points, the cluster centers will be re-computed for the next iteration. What will be the value of and ?
- A. , ,
- B. , ,
- C. , ,
- D. , ,
Answer and worked solution
Answer: D: Obj=7; new centers (0,0), (3.25,0)
- With initial centers (0,0) and (3,0), the five points around the origin join cluster 1; (3,0),(3,1),(3,−1),(4,0) join cluster 2.
- Using the initial centers, squared distances sum to 0+1+1+1+1=4 in cluster 1, and 0+1+1+1=3 in cluster 2. Obj=7.
- New means: the first cluster sums to (0,0). The second sums to (13,0), so its mean is . Do not recompute the requested objective using the new means.
ML Techniques Q7
In the context of EM algorithm, select all true statements from the options given below. There are data-points and mixtures. The index corresponds to the data-point, the index corresponds to the mixture. is the density of a Gaussian. All other symbols have their usual meaning.
- A.
- B.
- C.
- D.
Answer and worked solution
Answer: A and C
- πₖ=P(zᵢ=k) is the global prior probability of component k. Thus A is true.
- λₖⁱ=P(zᵢ=k|xᵢ) is the responsibility after observing xᵢ. Thus C is true.
- For each fixed i, , not generally . The latter is the effective component size Nₖ, so B is false. D is a Gaussian likelihood, not the normalized component posterior.
ML Techniques Q8
Consider a centered dataset of points in . Standard PCA is performed on this dataset. Consider the following ratio:
What is the minimum value of ?
Answer and worked solution
Answer: 0.2
- Let the five ordered covariance eigenvalues be λ₁≥…≥λ₅≥0. Their sum is total variance, and .
- Since every eigenvalue is at most λ₁, , hence θ≥1/5.
- Equality is attained when all five eigenvalues are equal and positive. If total variance is zero, the ratio is undefined.
ML Techniques Q9
Consider a centered dataset of points in . Standard PCA is performed on this dataset. What is the maximum number of principal components that can be retained so that the compression ratio does not fall below ? The compression ratio is defined as:
Assume that each real number occupies one unit of storage space. Note that we are interested in the reconstructions and not just in the scalar projections. So, the reconstructed dataset will also be in .
Answer and worked solution
Answer: 7 components (scores + basis storage)
- Original storage is nd=1000×10=10000 numbers. With m components, retain nm scores plus dm basis entries: 1010m numbers. Data are centered, so the mean need not add storage here.
- Require , giving . Therefore the largest integer m is 7.
- At m=7 the ratio is about 1.414; at m=8 it is about 1.238. If “reconstructed dataset” literally means all 1000 reconstructed 10D vectors stored explicitly, storage is still 10000 and the ratio is 1. The answer 7 uses the compressed representation needed for reconstruction.
ML Techniques Q10
Consider the dataset as shown in the figure. We want to project the dataset into another feature space so that it lives in a linear subspace of a higher-dimension space. We apply the kernel PCA with a polynomial kernel of the appropriate degree to achieve the same. What will be the dimension of transformed feature space?
Answer and worked solution
Answer: Uploaded answer: 3; kernel specification is needed
- The plotted samples follow a parabola. A chosen map has three coordinates; the relation becomes planar in these coordinates (a linear subspace after centering the ideal affine relation). This explains the uploaded answer 3.
- But this chosen map is not the full feature map of the standard inhomogeneous quadratic kernel . For 2D inputs that kernel has six features: .
- The question does not specify the polynomial kernel or whether it asks for a selected map, full feature-space dimension, or effective rank. A unique numerical answer cannot be justified as written. This question is review-only rather than automatically scored.
ML Techniques Q11
Consider a dataset with points in which all points are either or . We use a Bernoulli distribution with parameter to model this problem. The prior and posterior distributions for the parameter are and respectively. How many data-points have the value in this dataset? Note that as usual.
Answer and worked solution
Answer: 40 zeros
- For Bernoulli data with p=P(x=1), Beta(α,β) updates to Beta(α+ones, β+zeros).
- Ones=30−10=20; zeros=45−5=40.
- Check: 20+40=60 observations, matching the stated dataset size.
ML Techniques Q12
A GMM is fit for a dataset with points. At some time-step in the EM algorithm, the following are the values of for all points in the dataset for the mixture after the E-step:
What is the estimate of after the M-step?
Answer and worked solution
Answer: 0.7
- Effective component size: .
- The M-step weight is .
- Do not normalize this column to sum to 1: responsibilities sum to 1 across components for each individual point.
ML Techniques Q13
Is this dataset centered?
Four points in lie on a line through the origin:
- A. Yes
- B. No
Answer and worked solution
Answer: A: Yes
- Add coordinates separately: x-coordinates −2−1+1+2=0; y-coordinates −6−3+3+6=0.
- Divide by four points: mean=(0,0). A dataset is centered when its sample mean is zero.
ML Techniques Q14
Choose all representatives for this dataset such that .
Four points in lie on a line through the origin:
- A.
- B.
- C.
- D.
Answer and worked solution
Answer: A and B
- All points are scalar multiples of (1,3)ᵀ, so a representative direction must lie along that line.
- The length is . Dividing by √10 makes a unit vector.
- Either sign is valid: it reverses proxy signs but keeps the same line and reconstructions. C and D lie along the line but have lengths √10 and 2√10, not 1.
ML Techniques Q15
If standard PCA is performed on this dataset, what is the variance along the first principal component?
Four points in lie on a line through the origin:
Answer and worked solution
Answer: 25
- Use . Coordinates wᵀxᵢ are . Their mean is zero.
- Variance under the course convention is average squared coordinate: .
- Use denominator n=4, consistent with C=XXᵀ/n, rather than the unbiased sample-variance denominator n−1.
ML Techniques Q16
If standard PCA is performed on this dataset, what is the variance along the second principal component?
Four points in lie on a line through the origin:
Answer and worked solution
Answer: 0
- A unit second direction is perpendicular to (1,3), for example (−3,1)ᵀ/√10.
- Every point is on the first-component line, so every projection onto the second direction is zero.
- The variance of four zero coordinates is zero; all variance is captured by the first component.
ML Techniques Q17
What is the log-likelihood of this dataset under this distribution?
The four observations are assumed i.i.d. with density
- A.
- B.
- C.
- D.
Answer and worked solution
Answer: C
- For independent observations, , with θ>0.
- Apply log to each factor: .
- A is likelihood, not log-likelihood. B adds densities instead of their logs; D incorrectly multiplies the log terms. The listed positive observations in the next question avoid boundary log issues.
ML Techniques Q18
You are given the actual values of these observations:
What is the maximum likelihood estimate for ? Use wherever appropriate.
The four observations are assumed i.i.d. with density
Answer and worked solution
Answer: 0.4
- . Hence .
- Differentiate: , so θ̂=4/10=0.4.
- The second derivative is negative for θ>0, confirming the maximum.
ML Techniques Q19
Points:
The data are , , , and . For , find the k-means++ probability of choosing each listed pair as the initial centers in the specified order. Round to three decimal places.
Answer and worked solution
Answer: 0.044
- The ordered event requires x₂ first. The first center is uniform over five points, giving probability 1/5.
- Conditional on x₂=(2,0), squared distances to x₁,x₃,x₄,x₅ are 8,4,8,16; total=36. The selected point itself contributes distance 0.
- The probability of x₁ second is 8/36. Multiply: , rounding to 0.044.
ML Techniques Q20
Points
The data are , , , and . For , find the k-means++ probability of choosing each listed pair as the initial centers in the specified order. Round to three decimal places.
Answer and worked solution
Answer: 0.022
- The ordered event requires x₂ first. The first center is uniform over five points, giving probability 1/5.
- Conditional on x₂=(2,0), squared distances to x₁,x₃,x₄,x₅ are 8,4,8,16; total=36. The selected point itself contributes distance 0.
- The probability of x₃ second is 4/36. Multiply: , rounding to 0.022.
ML Techniques Q21
Points (in that order)
The data are , , , and . For , find the k-means++ probability of choosing each listed pair as the initial centers in the specified order. Round to three decimal places.
Answer and worked solution
Answer: 0.089
- The ordered event requires x₂ first. The first center is uniform over five points, giving probability 1/5.
- Conditional on x₂=(2,0), squared distances to x₁,x₃,x₄,x₅ are 8,4,8,16; total=36. The selected point itself contributes distance 0.
- The probability of x₅ second is 16/36. Multiply: , rounding to 0.089.
Quiz 1 source questions: ML Foundations
The following 25 questions are transcribed from the supplied mock_quiz_1_with_answers.md file embedded in the study site. The original question type, options, and available worked explanations are retained.
ML Foundations Q1
Let the function be continuous for all . Then, find the value of . Enter the answer correct to one decimal place.
Answer and worked solution
Answer: 3.5
- At x=2, the defined value is 4. The right-hand limit is 2×2=4.
- The left-hand limit is 2a−3; continuity requires 2a−3=4.
- Solve 2a=7 → a=3.5. The linear pieces are already continuous elsewhere.
ML Foundations Q2
Let , given by . Consider the following algorithm: and h > 0, where is the step size and is the gradient of evaluated at . Fix and , which among the following points does the algorithm converge to?
- A.
- B.
- C.
- D. The algorithm does not converge
Answer and worked solution
Answer: C: (0,0)
- For f(x,y)=x²+y², the gradient is (2x,2y)ᵀ=2X.
- With h=0.25, . Thus .
- Both coordinates tend to zero because |0.5|<1. This is convergence to (0,0), not just the first update (0.5,1.5).
ML Foundations Q3
Consider the following data set If is a classifier that is used to fit the data set, what is the resultant loss? Assume that Enter your answer correct to three decimal places.
Answer and worked solution
Answer: 0.167
- Compute scores x₁−3x₂ for the six points: 1,−4,0,−11,−7,−9.
- Using sign(0)=+1, predictions are +1,−1,+1,−1,−1,−1. Only the second point disagrees with its true label.
- Classification loss=wrong predictions / total=1/6≈0.167. The zero-score point is correct under the specified tie rule.
ML Foundations Q4
For the data set = 1 to 4, let the regression function be . The mean squared error loss obtained while fitting this function on the data set is
Answer and worked solution
Answer: 3.4
- For x=1,3,4,5, the predictions (x²−2)/5 are −0.2,1.4,2.8,4.6.
- Subtract targets 2,4,3,6: errors are −2.2,−2.6,−0.2,−1.4. Their squares are 4.84,6.76,0.04,1.96.
- Mean squared error=(4.84+6.76+0.04+1.96)/4=13.6/4=3.4.
ML Foundations Q5
A probability model is obtained by the density estimation algorithm for the data points and . Compute the (average) negative log likelihood loss of the model. (Note: Use log base 10.)
Answer and worked solution
Answer: 0.69897
- All five observations are inside [0,5], so each has model density 1/5.
- Average negative log-likelihood is .
- Numerically log₁₀5≈0.69897. Use base 10 as requested, not the natural logarithm.
ML Foundations Q6
The encoder and decoder functions expressed as and respectively are used to reduce the dimension of the data set given below. What is the loss obtained for the model?
Answer and worked solution
Answer: 5.148
- Compute each code u=f(x), reconstruct x̂=g(u), then calculate squared Euclidean error: sum the three squared coordinate errors.
-
Sample u g(u) ‖x−g(u)‖² (−1,1,−1) −2.5 (−0.75,2.5,−2.5) 4.5625 (1,2,1) −0.5 (−0.15,0.5,−0.5) 5.8225 (1,1,−1) −0.5 (−0.15,0.5,−0.5) 1.8225 (1,−1,2) 3 (0.9,−3,3) 5.01 (0,1,3) 0.5 (0.15,−0.5,0.5) 8.5225 - The squared errors sum to 25.74. Divide by five samples: loss=5.148. Do not divide again by the three features; this is mean squared vector reconstruction error.
ML Foundations Q7
Let Determine the equation of the tangent line at and use it to estimate the value of . Enter your answer correct to three decimal places.
Answer and worked solution
Answer: 2.527
- Product rule: .
- Tangent at a=0.5: . Here g(0.5)≈2.237328 and g′(0.5)≈2.893778.
- At x=0.6, displacement=0.1, so T(0.6)≈2.237328+0.289378=2.526706→2.527. Angles are in radians. This is the tangent estimate, not direct evaluation of g(0.6).
ML Foundations Q8
The directional derivative of at (1,1) in the direction of unit vector along is
Answer and worked solution
Answer:
- Partial derivatives: and . At (1,1), ∇f=(7,2)ᵀ.
- Normalize the direction: .
- Directional derivative: . The negative sign means f decreases along that direction.
ML Foundations Q9
Is the system consistent?
Let
- A. Yes
- B. No
Answer and worked solution
Answer: B: No
- The first two equations are x₁−x₂=1 and x₁+x₂=1. They force x₁=1,x₂=0.
- The third equation would then give x₁+2x₂=1, but its required right side is 3.
- No vector can satisfy all three equations; b is outside C(A).
ML Foundations Q10
Using the least square approximation, find the length of the projection vector of onto the column space of . Enter the answer correct to two decimal places.
Let
Answer and worked solution
Answer: 3.14
- Normal equations: , , so .
- The projection is .
- Take its length, not the coefficient length: , rounding to 3.14.
ML Foundations Q11
Which of the following matrices have eigenvectors as , ?
- A.
- B.
- C.
- D.
Answer and worked solution
Answer: A and B
- Use the test Mv=λv for each of the three vectors, not just one.
- Matrix A gives (16,8,16)ᵀ=8(2,1,2)ᵀ, (−1,2,0)ᵀ=−(1,−2,0)ᵀ, and (−1,0,1)ᵀ=−(1,0,−1)ᵀ. Thus all three are eigenvectors.
- B=2A preserves those eigenvectors and doubles the eigenvalues. C sends the first vector to (13,16,32)ᵀ; D sends it to (7,8,16)ᵀ. Neither result is a scalar multiple of (2,1,2)ᵀ, so C and D fail.
ML Foundations Q12
Let the matrix be diagonalizable, then which of the following statements is/are true for ?
- A. must be symmetric.
- B. We can find a basis of eigenvectors for .
- C. We can find an orthonormal basis of eigenvectors for .
- D. can have some repeated eigenvalues but it must have a sufficient number of linearly independent eigenvectors.
Answer and worked solution
Answer: B and D (diagonalizable over ℝ)
- Diagonalizability over the real numbers means d independent real eigenvectors exist; they form a basis of ℝᵈ. Thus B is true.
- Repeated eigenvalues are allowed if their eigenspaces supply enough independent eigenvectors in total. Thus D is true.
- Symmetry and an orthonormal eigenbasis are stronger properties, not guaranteed by diagonalizability. For example [[1,1],[0,2]] has two distinct eigenvalues and is diagonalizable, but is not symmetric. If diagonalization over ℂ were intended, the real-basis claim would need qualification.
ML Foundations Q13
The length of error vector obtained by projecting onto is
Answer and worked solution
Answer:
- Compute , , and .
- The projection is p=(13/14)v. Orthogonality gives .
- The question asks for length, so take the square root: about 2.988. Reporting 125/14 would give squared length instead.
ML Foundations Q14
Consider a line with zero slope and y-intercept of 2. The sum of squared residuals obtained when this line is used to fit the following data set is
Answer and worked solution
Answer: 6
- Zero slope and intercept 2 give the horizontal line ŷ=2 at every x.
- Observed-minus-predicted residuals are 0,2,−1,1. Square and add: 0+4+1+1=6.
- The question asks for the sum, not the mean; dividing by four would answer a different question.
ML Foundations Q15
If the matrix is reduced to its triangular echelon form, the number of free variables is
Answer and worked solution
Answer: 3
- Subtract row 1 from row 2: the result equals row 3, (0,0,1,2,3). There are only two independent rows/pivots.
- Pivot columns can be 1 and 3. Columns 2,4,5 correspond to free variables.
- Five unknowns minus rank 2 gives nullity=3, the number of free variables.
ML Foundations Q16
Find the cardinality of or the number of elements in .
Let be the set of all matrices , such that, two entries in are equal to and the other two are . For example, but .
Answer and worked solution
Answer: 6
- A 2×2 matrix has four positions. Exactly two must be chosen for ones; the rest become zero.
- The number of unordered choices is .
- Order of choosing the positions does not create a different matrix.
ML Foundations Q17
Which of the following is true?
Let be the set of all matrices , such that, two entries in are equal to and the other two are . For example, but .
- A. Every matrix in is diagonalizable.
- B. None of the matrices in are diagonalizable.
- C. There exists at least one matrix in that is not diagonalizable.
Answer and worked solution
Answer: A: Every matrix in S is diagonalizable
- Among the six matrices, four are rank one with trace 1. Their determinant is 0, so their eigenvalues are 0 and 1: distinct eigenvalues guarantee diagonalizability.
- The remaining two matrices are I₂ and [[0,1],[1,0]]. The identity is already diagonal; the swap matrix has eigenvalues 1 and −1.
- All six therefore have enough independent eigenvectors.
ML Foundations Q18
With the help of the previous question (or otherwise), determine if the following statement is true or false. If a square matrix is diagonalizable, then is invertible.
Let be the set of all matrices , such that, two entries in are equal to and the other two are . For example, but .
- A. True
- B. False
Answer and worked solution
Answer: B: False
- Diagonalizability requires a basis of eigenvectors. Invertibility additionally requires that no eigenvalue be zero.
- For example [[1,1],[0,0]] has eigenvalues 1 and 0: it is diagonalizable because they are distinct, but singular because the determinant is zero.
- Thus a diagonalizable matrix need not be invertible.
ML Foundations Q19
A row stochastic matrix is a square matrix with non-negative entries in which the sum of the entries in every row is equal to . If is a common eigenvalue every row stochastic matrix, then enter the value of .
Answer and worked solution
Answer: 1
- Let 1 denote the nonzero all-ones column. Each entry of A1 is the sum of one row of A.
- Every row sum is 1, so A1=1=1·1. Hence the eigenvalue 1 occurs in every row-stochastic matrix.
- No other value is common to all: the identity matrix is row-stochastic and has only eigenvalue 1.
ML Foundations Q20
Which of the following is/are true?
Consider the matrix given below: where .
- A. is an orthogonal matrix.
- B. is invertible.
- C. is symmetric
Answer and worked solution
Answer: A and B
- Multiply: because and the off-diagonal terms cancel. Therefore A is orthogonal.
- Its inverse is Aᵀ (also det A=1), so A is invertible.
- For 0<θ<180°, sin θ is nonzero. The off-diagonal entries −sin θ and +sin θ differ, so A is not symmetric.
ML Foundations Q21
Which of the following is true?
Consider the matrix given below: where .
- A. does not have real eigenvalues.
- B. has two distinct real eigenvalues.
- C. has two real eigenvalues, not necessarily distinct.
Answer and worked solution
Answer: A: No real eigenvalues
- The characteristic equation is .
- The roots are , where i is the imaginary unit.
- Because 0<θ<180°, sin θ≠0, so neither root is real. The endpoints where real roots occur are excluded.
ML Foundations Q22
Which of the following are the eigenvalues of ?
Consider .
- A.
- B.
- C.
Answer and worked solution
Answer: A:
- Multiply A by (1,−1)ᵀ: , giving eigenvalue 1.
- Multiply by (1,1)ᵀ: , giving eigenvalue 1/2.
- The eigenvalue sum 1.5 equals trace(A), and their product 0.5 equals det(A).
ML Foundations Q23
Consider the eigenvalue decomposition of given by , where is orthogonal and the diagonal elements of are arranged in decreasing order on the main diagonal. Which of the following could be ?
Consider .
- A.
- B.
- C.
Answer and worked solution
Answer: A
- Decreasing eigenvalue order puts the unit eigenvector for 1 first, then the unit eigenvector for 1/2.
- These are and . They are perpendicular and have unit length, giving Q in option A.
- B is not normalized. C is orthogonal but its columns are not eigenvectors of this A; orthogonality alone is insufficient.
ML Foundations Q24
Two matrices and are approximately equal if , for all , that is, the difference between every pair of corresponding elements is close to zero. Which of the following could be approximately equal to ? Choose the most appropriate answer.
Consider .
- A.
- B.
- C.
Answer and worked solution
Answer: A
- Write . Then .
- The second factor is negligible; only the eigenvalue-1 direction remains.
- Its unit eigenvector is . The limiting projector is , option A.
ML Foundations Q25
Suppose is a square matrix of order three with eigenvalues . What is the trace of ?
Answer and worked solution
Answer: 21
- Squaring a matrix squares its eigenvalues, with multiplicities: the eigenvalues of A² are 1,4,16.
- Trace equals the sum of eigenvalues, so trace(A²)=1+4+16=21.
- Do not square trace(A): (1+2+4)²=49 is not the requested quantity.
Source index
The identifiers below are the source file labels from the uploaded ML Exam Atlas. The original PDFs are not included in this blog package.
| ID | Source file | Collection | Week |
|---|---|---|---|
| S01 | week_1.pdf | archive1 | Week 1 |
| S02 | Slide 1.pdf | archive1 | Week 2 |
| S03 | Slide 2.pdf | archive1 | Week 2 |
| S04 | slide 1.pdf | archive1 | Week 3 |
| S05 | slide 2.pdf | archive1 | Week 3 |
| S06 | GMM_EM.pdf | archive1 | Week 4 |
| S07 | MLE_Bayesian.pdf | archive1 | Week 4 |
| S08 | 1. What is Machine Learning-.pdf | archive2 | Week 1 |
| S09 | 2. Data, Models and ML Task.pdf | archive2 | Week 1 |
| S10 | 3. Supervised Learning- Regression.pdf | archive2 | Week 1 |
| S11 | 4. Supervised Learning- Classification.pdf | archive2 | Week 1 |
| S12 | 5. Unsupervised Learning- Dimensionality Reduction.pdf | archive2 | Week 1 |
| S13 | 6. Unsupervised Learning- Density Estimation.pdf | archive2 | Week 1 |
| S14 | 1. Sets and Functions.pdf | archive2 | Week 2 |
| S15 | 2. Univariate Calculus- Continuity and Differentiability.pdf | archive2 | Week 2 |
| S16 | 3. Univariate Calculus- Derivatives and Linear Approximations.pdf | archive2 | Week 2 |
| S17 | 4. Univariate Calculus- applications and advanced rules.pdf | archive2 | Week 2 |
| S18 | 5. Multivariate Calculus- Lines and planes in higher dimensional space.pdf | archive2 | Week 2 |
| S19 | 6. Multivariate Calculus- Linear approximation and applications.pdf | archive2 | Week 2 |
| S20 | Week 2 Tutorial.pdf | archive2 | Week 2 |
| S21 | 1. Four Fundamental Subspaces.pdf | archive2 | Week 3 |
| S22 | 2. Orthogonal Vectors and Subspaces.pdf | archive2 | Week 3 |
| S23 | 3. Projections.pdf | archive2 | Week 3 |
| S24 | 4. Least Squares and Projections onto a Subspace.pdf | archive2 | Week 3 |
| S25 | 5. Example of Least Squares.pdf | archive2 | Week 3 |
| S26 | Week 3 Tutorial 3.1.pdf | archive2 | Week 3 |
| S27 | Week 3 Tutorial 3.2.pdf | archive2 | Week 3 |
| S28 | Week 3 Tutorial 3.3.pdf | archive2 | Week 3 |
| S29 | 1. Linear and Polynomial Regression.pdf | archive2 | Week 4 |
| S30 | 2. Eigenvalues and Eigenvectors.pdf | archive2 | Week 4 |
| S31 | 3. Diagonalization of a matrix.pdf | archive2 | Week 4 |
| S32 | 4. Solving Fibonacci Sequence using diagonalization.pdf | archive2 | Week 4 |
| S33 | 5. Orthogonally diagonalizable matrices.pdf | archive2 | Week 4 |
| S34 | Week 4 tutorial4.1.pdf | archive2 | Week 4 |
| S35 | Week 4 tutorial4.2.pdf | archive2 | Week 4 |
| S36 | Introduction_to_ML.pptx | archive1 | Week 1 |
| S37 | Week 1 Tutorial-1.docx | archive2 | Week 1 |