No history yet

Linear Algebra Basics

Vectors and Where to Find Them

At its heart, linear algebra is the study of vectors. You can think of a vector as an arrow in space. It has a specific length (magnitude) and points in a specific direction. In data science, we often use vectors to represent a collection of features. For example, a vector could represent a house, with its components being square footage, number of bedrooms, and price.

We usually write vectors as a column of numbers. A vector in a 2D plane, like a computer screen, has two components: one for the x-direction and one for the y-direction.

v=[32]\vec{v} = \begin{bmatrix} 3 \\ 2 \end{bmatrix}

This vector tells us to go 3 units to the right and 2 units up from the origin (the point (0,0)).

We can perform operations on vectors. Adding two vectors is like placing them tip-to-tail. The new vector, called the resultant, goes from the start of the first vector to the end of the second. Mathematically, we just add the corresponding components.

u=[13],v=[31]    u+v=[1+33+1]=[44]\vec{u} = \begin{bmatrix} 1 \\ 3 \end{bmatrix}, \quad \vec{v} = \begin{bmatrix} 3 \\ 1 \end{bmatrix} \implies \vec{u} + \vec{v} = \begin{bmatrix} 1+3 \\ 3+1 \end{bmatrix} = \begin{bmatrix} 4 \\ 4 \end{bmatrix}

We can also multiply a vector by a single number, called a scalar. This operation scales the vector, making it longer or shorter. Multiplying by a negative scalar flips its direction.

2v=2[31]=[2321]=[62]2 \cdot \vec{v} = 2 \begin{bmatrix} 3 \\ 1 \end{bmatrix} = \begin{bmatrix} 2 \cdot 3 \\ 2 \cdot 1 \end{bmatrix} = \begin{bmatrix} 6 \\ 2 \end{bmatrix}
Lesson image

Organizing with Matrices

A matrix is a grid of numbers, arranged in rows and columns. You can think of it as a collection of vectors or a way to organize data. For example, a grayscale image is just a matrix where each number represents the brightness of a pixel.

Matrices are fundamental structures in linear algebra that are crucial for understanding and implementing machine learning algorithms, particularly deep learning.

Like vectors, we can perform operations on matrices. Adding two matrices is straightforward: you just add the corresponding elements. This only works if the matrices have the exact same dimensions (the same number of rows and columns).

[abcd]+[efgh]=[a+eb+fc+gd+h]\begin{bmatrix} a & b \\ c & d \end{bmatrix} + \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} a+e & b+f \\ c+g & d+h \end{bmatrix}

Matrix multiplication is more involved. To find the element in the first row and first column of the resulting matrix, you take the first row of the first matrix and the first column of the second matrix. You multiply their corresponding elements and then sum the results. This is repeated for every row and column combination.

An important rule for matrix multiplication is that the number of columns in the first matrix must equal the number of rows in the second matrix. Also, unlike regular number multiplication, the order matters. In general, A×BA \times B is not the same as B×AB \times A.

Transformations and Eigen-things

So, why are matrices so useful? One of their primary roles is to describe linear transformations. A transformation is just a function that takes an input vector and spits out an output vector. When you multiply a matrix by a vector, you are transforming that vector—rotating it, stretching it, shearing it, or some combination of these.

Every matrix represents a specific linear transformation. This connection is the core of linear algebra.

When we apply a transformation to a vector space, most vectors get knocked off their original direction. But some special vectors are only stretched or shrunk by the transformation; their direction remains unchanged. These are called eigenvectors. The factor by which they are stretched or shrunk is their corresponding eigenvalue.

eigenvector

noun

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

This relationship is captured by a famous equation where AA is the matrix, v\vec{v} is the eigenvector, and λ\lambda (the Greek letter lambda) is the eigenvalue.

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

This equation says that transforming the vector v\vec{v} with matrix AA has the same effect as just scaling it by the number λ\lambda. Eigenvectors and eigenvalues reveal deep properties of a matrix and are fundamental to many algorithms in data science, like Principal Component Analysis (PCA) for dimensionality reduction.