Last modified: June 15, 2024

This article is written in: 🇺🇸

Linear Algebra Review

Linear Algebra forms the backbone of many machine learning algorithms, including linear regression. Understanding matrices and vectors is fundamental in this context.

Matrices Overview

matrix_element

Vectors Overview

Vector Representation

A vector can be represented as:

$$ y = \begin{bmatrix} x_{1} \\ x_{2} \\ \vdots \\ x_{m} \end{bmatrix} $$

where $x_{1}, x_{2}, ..., x_{m}$ are the elements of the vector.

Matrix Manipulation

Understanding matrix manipulation is essential in linear algebra and machine learning for organizing and processing data. Here are some fundamental operations:

Matrix Addition

Element-wise addition of two matrices of the same dimension.

matrix_addition

Important: The matrices must have the same number of rows and columns.

Multiplication by Scalar

Multiplying every element of a matrix by a scalar value.

matrix_mult_scalar

Multiplication by Vector

Multiplying a matrix with a vector.

matrix_mult_vector

Important: The number of columns in the matrix must equal the number of elements in the vector.

Multiplication by Another Matrix

Combining two matrices.

Procedure:

matrix_mult_matrix

matrix_mult_column

Important: The number of columns in the first matrix must match the number of rows in the second matrix.

Matrix Multiplication Properties

Matrix multiplication, a crucial operation in linear algebra, has specific properties that distinguish it from scalar multiplication.

Lack of Commutativity

I. For real numbers, multiplication is commutative.

$$3 \cdot 5 == 5 \cdot 3$$

II. The commutative property does not hold for matrix multiplication.

$$A \times B \neq B \times A$$

Associativity

I. Associative property holds for multiplication of real numbers.

$$3 \cdot (5 \cdot 2) == (3 \cdot 5) \cdot 2$$

II. Matrix multiplication is associative.

$$A \times (B \times C) == (A \times B) \times C$$

Identity Matrix

I. In scalar multiplication, 1 is the identity element.

$$z \cdot 1 = z$$

II. For matrices, the identity matrix $I$ serves as the identity element.

$$ I = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} $$

When multiplied by any compatible matrix $A$, it results in $A$ itself.

$$A \times I = A$$

Matrix Inverse

I. For non-zero real numbers, the multiplicative inverse holds.

$$x \cdot \frac{1}{x} = 1$$

II. Only square matrices can have an inverse. Not every square matrix has an inverse, analogous to how 0 has no multiplicative inverse in real numbers. Finding matrix inverses involves specific numerical methods.

matrix_inverse

Matrix Transpose

The transpose of a matrix $A$ of size $m \times n$ is another matrix $B$ of size $n \times m$, where the elements are flipped over its diagonal.

$B_{(j,i)} = A_{(i,j)}$.

matrix_transpose

Application in Machine Learning

Example: House Prices

Suppose there are multiple hypotheses to predict house prices based on different factors. With a dataset of house sizes, these hypotheses can be applied simultaneously using matrix operations.

For four houses and three different hypotheses:

This approach demonstrates how matrix multiplication can streamline the application of multiple hypotheses to a dataset, enhancing efficiency and scalability.

matrix_mult_use

Reference

These notes are based on the free video lectures offered by Stanford University, led by Professor Andrew Ng. These lectures are part of the renowned Machine Learning course available on Coursera. For more information and to access the full course, visit the Coursera course page.

Table of Contents

  1. Linear Algebra Review
    1. Matrices Overview
    2. Vectors Overview
      1. Vector Representation
    3. Matrix Manipulation
      1. Matrix Addition
      2. Multiplication by Scalar
      3. Multiplication by Vector
      4. Multiplication by Another Matrix
  2. Matrix Multiplication Properties
    1. Lack of Commutativity
    2. Associativity
  3. Identity Matrix
  4. Matrix Inverse
  5. Matrix Transpose
    1. Application in Machine Learning
    2. Example: House Prices
  6. Reference