Skip to content

    Linear Algebra for ML

    Machine Learning · Intermediate

    Definition

    Vectors, matrices, dot products and matrix multiplication are the language of ML models.

    Neural networks are mostly matrix multiplications.

    Diagram

    X (n×d)× W (d×1)= y (n×1)

    Flowchart

    Represent data as matrixWeights as matrixMultiply to predictTranspose / invert as needed

    Example: Matrix × vector

    X = [[1, 2], [3, 4]]
    w = [0.5, 1]
    print([sum(a * b for a, b in zip(row, w)) for row in X])

    Output: [2.5, 5.5]

    Key points

    • Dot product measures alignment
    • Shapes must match: (n×d)(d×k)

    Interview questions

    When is matrix multiplication valid?

    When the first matrix's columns equal the second's rows.

    More Machine Learning topics