Skip to content

Linear algebra reference

Use nn for records and dd for features. Our example has n=3n=3 and d=2d=2.

ExpressionMeaningShape or type
xix_iFeature measurements for record ii, as a columnd×1d\times1
xijx_{ij}Feature jj of record iiScalar
AAInputs, with record ii stored in row iin×dn\times d
wwOne weight per featured×1d\times1
yyObserved outputsn×1n\times1
AwAwOne prediction per recordn×1n\times1
ATA^\mathsf TRows and columns exchangedd×nd\times n
yAwy-AwResiduals: observed minus predictedn×1n\times1

These shapes use the convention that feature vectors are columns. A dataset row is therefore xiTx_i^\mathsf T.

uv=uTv=j=1dujvj,v2=vv.u\cdot v=u^\mathsf Tv=\sum_{j=1}^d u_jv_j, \qquad \lVert v\rVert^2=v\cdot v.

The dot product returns one number. The squared Euclidean norm adds squared entries. Both depend on the chosen coordinate scales.

(m×d)(d×k)(m×k),(AB)ij=r=1dAirBrj.(m\times d)(d\times k)\longrightarrow(m\times k), \qquad (AB)_{ij}=\sum_{r=1}^{d} A_{ir}B_{rj}.

Check the inner dimensions, then take each left-hand row dotted with each right-hand column. Matrix multiplication is not entry-by-entry multiplication, and changing order can change the answer or make a product undefined.

If a1,,ada_1,\ldots,a_d are the columns of AA, then

Aw=w1a1++wdad.Aw=w_1a_1+\cdots+w_da_d.

The column space contains all these linear combinations. Aw=yAw=y has an exact solution precisely when yy belongs to it. Independent columns give unique coefficients for every reachable output. Rank counts independent column directions.

For a nonzero vector aa, the projection onto its span is

p=aaTyaTa,aT(yp)=0.p=a\frac{a^\mathsf Ty}{a^\mathsf Ta}, \qquad a^\mathsf T(y-p)=0.

For several columns, least-squares weights satisfy

w^argminwyAw2,ATAw^=ATy.\widehat w\in\operatorname*{argmin}_w\lVert y-Aw\rVert^2, \qquad A^\mathsf TA\widehat w=A^\mathsf Ty.

The fitted prediction is unique; the weights are unique if the columns are independent. Writing (ATA)1ATy(A^\mathsf TA)^{-1}A^\mathsf Ty requires that independence. Solving the normal equations does not require explicitly forming an inverse.

For our example:

w^=[7/3,2/3]T,y^=[7/3,16/3,23/3]T,SSE=1/3,MSE=1/9.\widehat w=[7/3,2/3]^\mathsf T, \quad \widehat y=[7/3,16/3,23/3]^\mathsf T, \quad \mathrm{SSE}=1/3, \quad \mathrm{MSE}=1/9.

An intercept requires a constant input column. Minimizing training error is a fitting calculation; assessing new-data performance is a separate step.

Definition

Read the full glossary entry →