# <center><i class="fa fa-edit"></i> Basic Linear Algebra for Machine Learning </center>
###### tags: `notes`
:::info
**Goal:**
To understand what is 'Linear Algebra' and how is it used in Machine Learning
**Resources:**
[Introduction to Machine Learning](https://hackmd.io/T4oKVVPiRXqtD-k6a5h7Ug?both)
:::
## <b> The Matriks </b>
Matriks is the heart of Linear Algebra. A matrix is essentially bunch of numbers stored between 2 brackets in a tabular manner.

## What could these number in the matrix be?
Here are a couple of example :point_down:
- Pixels in an image
Left is an image of '8' and on the right is a matrix showing the numerical values of each pixel (black-0, white-255).

- Tabular Data from an excel sheet

### <b>We represent matrices (plural for a matrix) in Python using a LoL (List of Lists). </b>
==matrix = [[1,2,3],
     [4,5,6],
     [7,8,9]]==
### <b> The below picture shows the mathematical notation for writing matrices. </b>
'i' denotes the number of terms on the Y-axis and 'j' denotes the number of terms on the X-Axis in the Matrix.


### Transpose of a Matrix
'Transpose' is one way to transform a matrix. Imagine you have an imaginary line going from the top-left corner of the matrix to the bottom right, and then you interchange the opposite values.
The matrix you get after switching the values is the transpose of the matrix.

Think of a transpose as flipping the matrix along the red line.
<i> <b> In mathematical notation, a transpose is denoted by a small 'T' at the top of the letter that was originally assigned to the matrix</b></i>

### <b> Identity Matrix</b>
There is a special type of matrix called the 'identity' matrix. They look like this (basically the top-left to bottom-right diagonal consist of 1s and the other values are 0s.)

### <b> Adding, Substracting, and Multiplying matrices</b>
We can also add, substract or multiply matrices. Adding and subtracting matrices is as simple as adding/subtracting the corresponding values of the matrices.

On the other hand, multiplying matrices is a bit tricky. It looks somewhat like this :point_down:

It probably doesn't make sense, which is why you should look at this [site](https://mathsisfun.com/algebra/matrix-multiplying.html).
### But, why is Linear Algebra important in Machine Learning?
Let's say we want to make a machine learning model that can recognize numbers in a given image.
We can't just give this image to a computer and ask "Hey, what number is in this image?"

We need to convert that image into something that a computer can understand, like a LoL (List of List) which is a representation of matrix in Python.

<i><b> Many times we need to transform this matrix in a way that our machine learning model wants it to be. </b></i>
It could be a transpose, addition, or multiplication but I won't get into the spesifics of it.
### <b> Another thing that you must know about is the difference between a Scalar, Vector, and Matrix.</b>
- Scalar: Just a number
- Vector: A row or column of numbers between brackets
- Matrix: Numbers in a tabular form between brackets with multiple rows and columns.
