Linear Algebra
Linear Algebra
Machine learning has a strong connection with mathematics. Each machine learning
algorithm is based on the concepts of mathematics & also with the help of mathematics, one
can choose the correct algorithm by considering training time, complexity, number of
features, etc. Linear Algebra is an essential field of mathematics, which defines the study of
vectors, matrices, planes, mapping, and lines required for linear transformation.
Linear algebra plays a vital role and key foundation in machine learning, and it enables ML
algorithms to run on a huge number of datasets.
The concepts of linear algebra are widely used in developing algorithms in machine learning.
Although it is used almost in each concept of Machine learning, specifically, it can perform
the following task:
Optimization of data.
Applicable in loss functions, regularisation, covariance matrices, Singular Value
Decomposition (SVD), Matrix Operations, and support vector machine classification.
Implementation of Linear Regression in Machine Learning .
Linear Algebra is just similar to the flour of bakery in Machine Learning. As the cake is
based on flour similarly, every Machine Learning Model is also based on Linear Algebra.
Further, the cake also needs more ingredients like egg, sugar, cream, soda. Similarly,
Machine Learning also requires more concepts as vector calculus, probability, and
optimization theory. So, we can say that Machine Learning creates a useful model with
the help of the above-mentioned mathematical concepts.
Below are some linear Algebra concepts which are mostly used in
Machine Learning implementation: Associative Property: It is a
property in Mathematics which states that if a, b and c are mathematical
objects than a + (b + c) = (a + b) + c in which + is a binary operation.
Commutative Property: It is a property in Mathematics which states that
if a and b are mathematical objects then a + b = b + a in which + is a
binary operation.
Distributive Property: It is a property in Mathematics which states that
if a, b and c are mathematical objects then a * (b + c)= (a * b) + (a * c) in
which * and + are binary operators.
Below are some linear Algebra concepts which are mostly used in
Machine Learning implementation:
Here V is a vector in which e1, e2, e3 and e4 are its elements, and V[2] is
e3.
Example:
[2, 3, 4] and [34, 53]
Operations:
Scalar-Vector Multiplication:
when the scalar 2 is multiplied by a vector p then all the elements of the vector p is multiplied
by that scalar. This operation satisfies commutative property.
Example:
x = [1, 2]
x * 4 = [4, 8]
MATRICES:
columns.
Above M is a 2D matrix having e1, e2, e3 and e4 as elements, and M [1][0] is e3.
Example:
2 3 6 and 56 12
458 45 78
34 67
A matrix having its left diagonal elements as 1 and other elements 0 is an Identity
matrix.
Example:
10
0 1 is 2D Identity Matrix.
100
010
0 0 1 is 3D Identity Matrix.
Operations:
Scalar-Vector Multiplication:
p = [e1, e2, e3]
The product of a scalar with a vector gives the below result-
1. (A * B) * C:
2. (A * B) * C = | 1*3+2*9 1*4+2*10 | * | 5 6 |
| 7*3+8*9 7*4+8*10 | |11 12 |
= | 21+18 4+20 | * | 5 6 |
| 63+72 28+80 | |11 12 |
= | 39 24 | * | 5 6 |
| 135 108 | |11 12 |
3. A * (B * C):
A * (B * C) = | 1 2 | * | 3*5+4*11 3*6+4*12 |
| 7 8 | | 7*5+8*11 7*6+8*12 |
= | 1 2 | * | 73 78 |
| 7 8 | | 107 118 |
= | 1*73+2*107 1*78+2*118 |
| 7*73+8*107 7*78+8*118 |
= | 253 314 |
| 581 766 |
A * (B * C) = | 253 314 |
| 581 766 |
2. Distributive Property:
The distributive property of matrix multiplication states that you can distribute the
multiplication of a matrix across a sum (or difference) of matrices. In mathematical
terms:
A * (B + C) = (A * B) + (A * C)
Here's a more detailed explanation:
Suppose you have three matrices, A, B, and C, and you want to multiply matrix A by
the sum of matrices B and C.
You can achieve the same result by separately multiplying A by B and A by C and
then adding the results together.
Numerical Example:
Using matrices, A, B, and C from the previous example:
A * (B + C) = | 1 2 | * (| 3 4 | + | 5 6 |)
| 7 8 | | 9 10 | |11 12 |
= | 1 2 | * | 3+5 4+6 |
| 7 8 | | 9+11 10+12 |
= | 1 2 | * | 8 10 |
| 7 8 | |20 22 |
2. (A * B) + (A * C):
(A * B) + (A * C) = | 1*3+2*9 1*4+2*10 | + | 1*5+2*11 1*6+2*12 |
| 7*3+8*9 7*4+8*10 | | 7*5+8*11 7*6+8*12 |
= | 21+18 4+20 | + | 5+22 6+24 |
| 63+72 28+80 | | 35+88 42+96 |
= | 39 24 | + | 27 30 |
| 135 108 | |123 138 |
(A * B) + (A * C) = | 39 24 | + | 27 30 | = | 66 54 |
| 135 108 | |123 138 | |258 246 |
A * (B + C) = | 8 12 |
| 36 50 |
(A * B) + (A * C) = | 66 54 |
| 258 246 |
INVERSE OF MATRIX:
Inverse of a Matrix is a matrix that on multiplying with the original matrix result in
the identity matrix. It is required to solve complex problems using matrix operations.
For any matrix A its inverse is denoted as A -1.
A.A-1 = A-1A = I
Where I is the identity matrix.
|34|
To find the inverse of B, we can use the formula for a 2x2 matrix:
B^ (-1) = (1 / det(B)) * | d -b |
| -c a |
Where:
In our case:
-a=2
-b=1
-c=3
-d=4
det(B) = (2 * 4) - (1 * 3) = 8 - 3 = 5
B^ (-1) = (1 / 5) * | 4 -1 |
| -3 2 |
| -3/5 2/5 |
This is how you find the inverse of a 2x2 matrix. For larger matrices, you may need to use
calculation becomes more complex. In machine learning, matrix inverses are often used in
TRANSPOSE OF A MATRIX
1. Matrix Transpose:
- The transpose of a matrix A, denoted as A^T or A', is obtained by switching its rows
with columns.
- The (i, j)-th element of A^T is the same as the (j, i)-th element of A: (A^T)_ij = A_ji.
Transpose is used in various machine learning operations, such as when you need to
convert feature vectors into column vectors or when dealing with covariance matrices.
Matrix Transpose Example:
A=|123|
|456|
A^T = | 1 4 |
|25|
|36|