Linear Regression: The Inception— Samur.AI

Rohan Saha
Samur.AI
Published in
3 min readJan 25, 2019

Introduction

Newbies to machine learning often become inundated with the mathematics encompassing the whole subject. Guess what? It is not that difficult to get into machine learning. Just like any other subject, you spend some time with it, and boom! you become familiar with the subject.

Take any skill in life, you will no doubt require some definite background to master that skill or at least be proficient in it. Similarly, in machine learning, mathematics is one of the most important prerequisites.

Hold On! Don’t lose hope. In this short article, you will gain interest in the subject like never before….

You might have heard that you need to be strong in areas like calculus and statistics, but I believe that only an introductory knowledge is sufficient. In fact, many online courses only require basic differential calculus and linear algebra (matrix arithmetic) to at least feel comfortable with the subject. Therefore, keep calm and love maths!

Enough said, let’s start off with the most basic algorithm that is under the umbrella of machine learning. LINEAR REGRESSION!

Observe the following picture. What do you see?

If you look closely, you will see that as the temperature increases, the number of chirps per minute increases as well. Though not perfect, there is somewhat a linear (direct) relationship between the temperature and the chirping rate.

NB: If machine learning, you may find variables being named as ‘x1 and x2 instead of ‘x’ and ‘y’. Do not become confused, they are the same thing.

This is a case of simple linear regression. Why ‘simple’? Because there is only one variable on which the chirping rate depends, ‘temperature’.

Easy right?

In our case, the temperature is the independent quantity and the chirping rate is the dependent quantity. This example demonstrates that the axis of representation does not matter as long as the dependent and independent variables are stated clearly.

Understood? Good!

Warning! (Very Simple) Math ahead!

Have a look at the following equation:

y = mx +c

If you are in high school or college, you may easily recognize the equation. This is the equation for a straight line.

Explanation

Here, ‘y’ is the dependent variable or the result, ‘x’ is the independent variable, ‘m’ is the slope of the line. and ‘c’ is the intercept (the point at which the line intersects the y-axis).

Got it? Good!

In machine learning, you will frequently see that ‘m’ is replaced by ‘w’, and ‘c’ is replaced by ‘b’. They are basically the same thing. In addition, ‘w’ stands for weight and ‘b’ stands for bias. The meaning is same as that of slope and intercept.

y = wx +b

So, what we do is, we try to draw a straight line on the data on the graph given above so that that the line models a good relationship between the dependent and independent variable(s).

Something like this:

The following is your ultimate goal in any machine learning problem:

Given the set of data points, find an optimal model(line) that models the relationship between the input and output.

How can you find a model(line) that fits the data given? That is a topic for another article.

Summary

Linear regression is one of the most basic and simple algorithms where there is only one independent variable on which the output is to be calculated. In this short article, you got an idea about simple linear regression and an extremely basic idea about machine learning in addition to some math. In the following articles, you will learn about how to find the straight line and the different types of regression models.

If you like this article, consider buying me a coffee :)

--

--

Rohan Saha
Samur.AI

I write about byte sized articles on machine learning and how to survive academia.