No history yet

Linear Algebra

Vectors and Matrices: The Language of Data

In machine learning, data is almost always represented using vectors and matrices. Think of them as the fundamental building blocks for organizing and manipulating information. A vector is a list of numbers, and a matrix is a grid of numbers. For example, we could represent a house by a vector containing its features: [square footage, number of bedrooms, distance from city center].

Vector

noun

An ordered list of numbers. Geometrically, it represents a point or a direction in space.

We can perform basic operations on vectors. When we add two vectors, we simply add their corresponding components. This is like taking two steps and finding the total displacement.

(ab)+(cd)=(a+cb+d)\begin{pmatrix} a \\ b \end{pmatrix} + \begin{pmatrix} c \\ d \end{pmatrix} = \begin{pmatrix} a+c \\ b+d \end{pmatrix}

We can also scale a vector by multiplying it by a single number, called a scalar. This changes the vector's magnitude (length) but not its direction.

k(ab)=(kakb)k \cdot \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} k \cdot a \\ k \cdot b \end{pmatrix}

A matrix is just a collection of vectors stacked together. If we had data for multiple houses, we could organize them into a matrix, where each row represents a house and each column represents a feature.

Matrix

noun

A rectangular array or table of numbers, symbols, or expressions, arranged in rows and columns.

Like vectors, matrices can be added and multiplied by scalars. The rules are the same: you operate on corresponding elements. Where things get more interesting is matrix multiplication. Multiplying two matrices is a core operation in machine learning, especially in neural networks. It combines information from both matrices in a systematic way.

The rule is to multiply rows from the first matrix by columns from the second matrix. The element in the ii-th row and jj-th column of the resulting matrix is the dot product of the ii-th row of the first matrix and the jj-th column of the second.

(abcd)(efgh)=(ae+bgaf+bhce+dgcf+dh)\begin{pmatrix} a & b \\ c & d \end{pmatrix} \begin{pmatrix} e & f \\ g & h \end{pmatrix} = \begin{pmatrix} ae+bg & af+bh \\ ce+dg & cf+dh \end{pmatrix}

The Determinant

For any square matrix, we can calculate a single number that tells us something profound about the transformation it represents. This number is the determinant.

Geometrically, the determinant of a matrix tells you how much the area (in 2D) or volume (in 3D) of a space gets scaled when you apply the matrix as a transformation. If you transform a square with an area of 1, the area of the resulting parallelogram will be the absolute value of the determinant.

A determinant of 0 means the transformation squishes space into a lower dimension, like collapsing a square into a line. A negative determinant means the transformation flips the orientation of space, like turning it into a mirror image.

For a 2x2 matrix, the calculation is straightforward.

det(abcd)=adbcdet \begin{pmatrix} a & b \\ c & d \end{pmatrix} = ad - bc

Eigenvalues and Eigenvectors

When a matrix acts on a vector, it usually changes the vector's direction. However, for any given matrix, there are special vectors that don't change their direction at all. They only get stretched or shrunk. These are called eigenvectors.

Eigenvector

noun

A non-zero vector that changes by only a scalar factor when a linear transformation is applied to it.

The scalar factor by which an eigenvector is stretched or shrunk is called its eigenvalue.

Eigenvalue

noun

The scalar factor by which an eigenvector is scaled when a linear transformation is applied.

This relationship is captured by one of the most important equations in linear algebra.

Av=λvA\vec{v} = \lambda\vec{v}

Imagine a transformation that stretches everything horizontally. Any horizontal vector is an eigenvector because its direction doesn't change, it just gets longer. Its eigenvalue would be the stretch factor. A vertical vector would also be an eigenvector, but its eigenvalue would be 1, since it isn't stretched at all.

Eigenvectors and eigenvalues are critical in machine learning. They help us find the most important directions or principal components in a dataset, which is the basis for dimensionality reduction techniques like Principal Component Analysis (PCA). They essentially reveal the underlying structure of the data by identifying the axes of greatest variance.

Let's test your understanding of these fundamental concepts.

Quiz Questions 1/6

In machine learning, what is a vector typically used to represent?

Quiz Questions 2/6

Given two vectors, A = [2, 8, 3] and B = [7, 1, 5], what is their sum?

Vectors, matrices, determinants, and eigenvectors form the mathematical foundation for many powerful machine learning algorithms. Understanding them is the first step toward understanding how these models truly work.