Linear Regression | The idea of the old and the model of the future

A brief essay to help you begin with the basics of Machine Learning

vasanth ambrose
PerceptronAI
6 min readJul 2, 2020

--

Photo by Philippe Donn from Pexels

Have you ever wondered how our mobile phones recognize our voice, text, and images? And how it interacts like a human to give us the exact results — like video recommendation on Youtube and Netflix? Mostly it sounds strange but this improvement in the field of Artificial Intelligence has produced such great results.

What is Machine learning?

It is the ability of a computer to learn without being explicitly programmed. Machine learning is a subfield of Artificial Intelligence.

To understand how a machine learns we can refer to the image shown below.

Deep Learning with Python by François Chollet

This is known as the paradigm of programming. The first one is the classical way of programming where you feed the input with some sort of rules to get the desired output.

Whereas, if we look at the machine learning paradigm we feed the input and output to a machine learning algorithm and the machine finds the logic or rule for us which can be used to draw new answers or predictions.

There are three prominent categories of machine learning.

  • Supervised learning
  • Unsupervised learning
  • Reinforcement learning

There is something important in machine learning that we should understand to know what really happens under the hood. There is a series of algorithms that endeavors to recognize the underlying relationships in a set of data.

Data as leverage for machine learning models

We can see data all around us, it is now the most available resource in the world. We can’t let it go waste. So we use this data to train a model — or in other words, find the rules — such that it predicts answers for any other new data which we enter.

Where does this help us?

It comes to help us from the start to the end of the day.

  • From recommending videos and music.
  • Personalizing the websites and apps we use according to our way.
  • It’s used in skin cancer detection.
  • Weather forecasting
  • Stock markets
  • Investment in banks
  • Predicting the price of a house.
  • Interestingly as said before it’s used in voice recognition, image identification, text detection, sentimental analysis, machine translation, and so on.

Linear Regression

Let’s talk about Linear Regression:

Under supervised learning, there is a type known as “Regression”. It is a popular learning algorithm that learns a pattern which is a linear combination of numbers of the input example. See the image below.

When there is a collection of labeled data, the Linear Regression tries to plot a line through the data points and so it can later predict the result when a different input is given.

The first step that takes place is that we train the model. During this time it tries to find the function f(x). Let’s take an example to understand better.

f(X) = y

where:

  • X is the independent variable
  • y is the dependent variable because it depends upon the input we give.

Linear regression uses a linear function or relationship which can be written as :

y = wX + b

This is the equation of a straight line. During the training process, it tries to assign random numbers to w and b and tries to satisfy the input and the output which was entered during the training process by correcting the randomly assigned w and b such that it finds the best fit or the actual parameters.

primo.ai/index.php?title=Linear_Regression

The whole idea of machine learning is to find the parameters w and b.

This is like the teacher teaching the student a problem in math until the student understand the logic.

Once the training process gets over we enter only the X value and the Linear Regression finds y, as it now knows which value of m and c can satisfy the straight-line function.

Now it’s like the student writing an exam to test his level of understanding

The Mathematical Intuition

To understand how Linear Regression works we need to understand the math behind it as to how it finds w and b :

Here we have to understand the concept of gradient descent”.

It is an optimization algorithm to find the lowest possible value — in our case 0.

Source: https://towardsdatascience.com/neural-networks-with-numpy-for-absolute-beginners-part-2-linear-regression-e53c0c7dea3a

When we get the data we usually get independent and the dependent values. As a machine learning engineer all, we want is to find the relationship between the same.

To begin with:

  1. We randomly assign value for w and b so that we can get a random solution. Let’s call this y_pred = wX + b
  2. Once we have the random predicted value of y, we subtract it with the original y, and hence we find the error.
error = y_original — y_pred

3. Now we square of that error and find its mean. This is known as the mean squared error.

This makes the process faster because finding the median or mean could take a lot of time. It is due to the fact that we are dealing with vast data. Since we have the mean square error we find the partial derivative of the function which is quicker — it is like finding a displacement for the longest distance.

db = -2 * mean square error
dw = -2 * x * mean square error

4. Next, we perform a range of iterations: updating w and b;

b = b — learning_rate * dbw = w — learning_rate * dw

Where the learning rate controls how quickly the model is adapted to the problem. It can be a small positive number such as 0.01 or 0.001.

Iteration is done until the error becomes zero and so the predicted y becomes equal to the original value of y.

This is how gradient descent works to find the values of w and b by itself. Now the model is ready.

source: https://towardsdatascience.com/neural-networks-with-numpy-for-absolute-beginners-part-2-linear-regression-e53c0c7dea3a

The way how Linear Regression work is interesting and it forms the basis for Machine Learning. This same model is being made much more complex and it is being used to unravel the mysteries of the universe.

Machine learning is the future that awaits. This is going to help us all to reach even greater aspects of making our lives comfortable.

AlphaGo by DeepMind has proved how Artificial Intelligence surpasses human thinking.

Neuralink is on its march to reach the highest way for humans to interact with machines.

It is right for us to conclude that Artificial Intelligence is making the world a better place to live.

Recommended Videos:

  1. AlphaGo: DeepMind
  2. Neuralink: Cold Fusion
  3. Who Invented A.I.? — The Pioneers of Our Future: Cold Fusion
  4. This Canadian Genius Created Modern AI:
    Bloomberg QuickTake Originals

In the next blog, we will ponder upon the idea of Neural Networks and its working.

--

--