Math preliminaries

Sonu Ranjit Jacob
3 min readMay 26, 2020

In my opinion, machine learning is a combination of mathematics and computer science. So of course there is some math that you need to know before we start off with actually making machines learn some data to make accurate predictions! I will cover only the basics in this post and explain it in detail in my future posts.

First off, matrix operations. Most of the machine learning models work with matrices as it is more efficient (this is also because it allows parallel computing).

A matrix is defined by its rows and columns. The below matrix A has a dimension of 2 * 3 where 2 is the number of rows and 3 is the number of columns. Similarly, B has a dimension of 3*2.

A (2*3), B(3*2)

For matrix addition and subtraction, the dimensions of the matrices must be equal.

Matrix Addition

For matrix multiplication, the number of columns for the first matrix should be equal to the number of rows for the second matrix. So if I am multiplying matrix A (dimension m*n) by matrix B (dimension n*k), the result is an m*k matrix. I visualise an inverted L to remember which numbers to multiply.

Second, graphing of linear equations. This is important for concepts like linear classification which I will cover in my next post. Given a line represented by y = 2x + 2, I can graph it by substituting the values of x and obtain the corresponding value of y. So, when

x =0, y = 2*0 + 2 = 2 giving the point (0, 2)

x =2, y = 2*2 + 2 = 6 giving the point (2, 6)

x =3, y = 2*3 + 2 = 8 giving the point (3, 8)

If I plot these points on the x and y axes and join them, I obtain the following graph. It is observed that if I draw a line at x = 2 to meet my line and I project that line to the y axis, y = 6.

Plot of the line y = 2x + 2

The next important concept is probability theory. Probability gives us a measure of how often an event could occur. For example if I say the probability of John forgetting his umbrella is 0.9, then it means 9 times out of ten, John has forgotten to bring his umbrella.

Consider another example where I have a bag of 3 red and 7 blue balls. Now if I have to pick a ball and predict the probability of it being a red or blue ball, I will use the following formula

Probability (red) = Number of red balls/Total number of balls = 3/7 = 0.42

That means approximately if I pick a ball at random out of the bag, 4 times out of ten, the picked ball will be red in colour.

These are the most fundamental topics in mathematics required for machine learning, I will explain more about each topic in detail as we implement machine learning models. That’s all for now!

--

--