Linear Algebra Operations For Machine Learning (original) (raw)

Last Updated : 20 Aug, 2025

Linear algebra is a core mathematical foundation for machine learning, as most datasets and models are represented using vectors and matrices. It allows efficient computation, data manipulation and optimization, making complex tasks manageable.

Fundamental Concepts in Linear Algebra for Machine Learning

In machine learning, **vectors, **matrices and **scalars play key roles in handling and processing data.

**1. Vectors

Vectors are quantities that have both magnitude and direction, often represented as arrows in space.

\mathbf{v} = \begin{bmatrix} 2 \\ -1 \\ 4 \end{bmatrix}

**2. Matrices

Matrices are rectangular arrays of numbers, arranged in rows and columns. Matrices are used to represent linear transformations, systems of linear equations and data transformations in machine learning.

**Example: \begin{bmatrix}1 & 2 & 3 \\4 & 5 & 6 \\7 & 8 & 9\end{bmatrix}u = [3, 4] v = [-1, 2].

3. Scalars

Scalars are single numerical values, without direction, magnitude only. Scalars are just single numbers that can multiply vectors or matrices. In machine learning, they’re used to adjust things like the weights in a model or the learning rate during training

**Example: Let's consider a scalar, k= 3 and a vector [\mathbf{v} = \begin{bmatrix} 2 \\ -1 \\ 4 \end{bmatrix}]
Scalar multiplication involves multiplying each component of the vector by the scalar. So, if we multiply the vector v by the scalar k= 3 we get:
k \cdot \mathbf{v} = 3 \cdot \begin{bmatrix} 2 \\ -1 \\ 4 \end{bmatrix} = \begin{bmatrix} 3 \cdot 2 \\ 3 \cdot (-1) \\ 3 \cdot 4 \end{bmatrix} = \begin{bmatrix} 6 \\ -3 \\ 12 \end{bmatrix}

Operations in Linear Algebra

**Addition & Subtraction: Add or subtract corresponding elements of vectors/matrices.
**Example:
u = [ 2, −1, 4], v = [ 3, 0, −2]
u +v = [ 5, −1, 2], u −v = [ −1, −1, 6]

**Scalar Multiplication: Multiply each element by a scalar.
**Example: 3⋅ [ 2, −1, 4] = [ 6, −3, 12]

**Dot Product: Measures similarity of directions by multiplying matching elements and summing.
**Example: u⋅ v= u1v1+ u2v2+ u3v3

**Cross Product: For 3D vectors, produces a new vector perpendicular to both.
**Example: u ×v = [u2v3− u3v2, u3v1 −u1v3, u1v2−u2v1 ]

Linear Transformations

Linear transformations are basic operations in linear algebra that change vectors and matrices while keeping important properties like straight lines and proportionality. In machine learning, they are key for tasks like preparing data, creating features and training models. This section covers the definition, types and uses of linear transformations.

**Definition: A transformation T is linear if it satisfies:

**Common Types in ML

Matrix Operations

Matrix operations are central to linear algebra and widely used in machine learning for data handling, transformations and model training. The most common ones are:

Eigenvalues and Eigenvectors

Eigenvalues and eigenvectors describe how matrices transform space, making them fundamental in many ML algorithms.

**Example: For A = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix}

solving det⁡(A−λI) = 0 gives λ1 = 1,λ2 = 3.

**Eigen Decomposition: A = Q \Lambda Q^{-1}

where Q holds eigenvectors and Λ is diagonal with eigenvalues.

**Applications in ML:

Solving Linear Systems of equations

Linear systems are common in machine learning for parameter estimation and optimization. Key methods include:

**1. Gaussian Elimination: Transforms a matrix into row-echelon form using row operations. Steps:

**2. LU Decomposition: Splits a matrix into Lower (L) and Upper (U) triangular matrices. Solves systems efficiently using forward and back substitution.

**3. QR Decomposition: Splits a matrix into Orthogonal (Q) and Upper triangular (R). Useful for least squares problems and eigenvalue computation.

Applications of Linear Algebra in Machine Learning

Linear algebra powers many ML algorithms by enabling data manipulation, model representation and optimization. Key applications include: