Matrices - The Dataset
Building upon scalars (single numbers) and vectors (lists of numbers), a Matrix is a rectangular array of numbers arranged in rows and columns. In Machine Learning, matrices are the primary mathematical objects used to represent entire datasets and the parameters (weights) of a model.
1. What is a Matrix?
A matrix is an organized collection of scalars, where each scalar is precisely located by its row and column index.
Notation and Representation
Matrices are typically denoted by bold, uppercase letters (e.g., ).
A matrix with rows and columns is called an matrix (read as "m by n").
- Elements: refers to the scalar element located in the -th row and -th column.
- Dimensions/Shape: The shape of is .
2. Matrices in Machine Learning
A. The Dataset Matrix ()
The entire dataset used to train an ML model is commonly represented as a matrix .
- Rows (): Each row represents a single data sample (or vector, ). If you have 1000 houses, .
- Columns (): Each column represents a single feature (or variable). If you track size, bedrooms, and age, .
For 1000 houses with 3 features: is a matrix.
B. Weight Matrices ()
In Deep Learning, the connections between layers of a neural network are represented by weight matrices.
- If a layer has inputs and outputs (neurons), the weight matrix connecting them has the shape .
- Matrix multiplication () is the fundamental computation in all neural networks.
3. Special Types of Matrices
Certain matrices have unique properties that are vital in solving systems of equations, statistical modeling, and transformations.
| Matrix Type | Description | Example () | ML Application |
|---|---|---|---|
| Square Matrix | Number of rows equals number of columns (). | Used for calculating determinants, inverses, and eigenvalues. | |
| Identity Matrix () | A square matrix with ones on the main diagonal and zeros everywhere else. | Acts as the number '1' in matrix multiplication (). | |
| Symmetric Matrix | equals its own transpose (). | Covariance matrices (in statistics/PCA) are always symmetric. |
4. Vector as a Matrix
A vector can be considered a special case of a matrix:
- Column Vector: An matrix.
- Row Vector: A matrix.
5. Matrix Operations (Preview)
We will dedicate the next section to matrix operations, but here are the key concepts that define how matrices interact:
A. Matrix Transpose ()
The transpose flips the matrix over its diagonal, turning rows into columns and columns into rows. If is , is .
If (3x2), then (2x3).
B. Matrix Multiplication ()
This is the single most important operation in ML. It is not element-wise. The product is only defined if the number of columns in equals the number of rows in .
In a neural network, if is the input data matrix and is the weight matrix, the computation for the first layer is . This single operation efficiently calculates the weighted sum for all data samples at once.
Matrices are the backbone for representing data and model parameters. The operations performed on these matrices are what allow ML algorithms to learn.