Summer Training Program | Day 4 | Linux World | Vimal Daga

Agenda: Internal concepts of Regression Algo and Docker

Sarath Kumar R S
6 min readMay 26, 2021

This is day 4 of our training and we have been training our model on a demo dataset which is an ideal one and not a realistic data. The whole and sole motive of previous practical was to make you comfortable with ML and the terminologies. Today we will see what is the internal concept and how algorithm is working behind the scene and we will jump into a new interesting technology.

As we have been working with continuous targets, we are using the Regression Algorithm. Let’s see how this is working with a more realistic data, earlier we just used very co-related data, in real world there will be someone who study 4 hours and score 80 marks. The dataset we are going to use will be a slight modified example we used before. We can exclude the names as is not a feature, we only need the hours of study and marks.

For the machine to predict the mark, we need the co-efficent / weight.

y = wx

y is the target here it is marks, x is the feature and here it is hours of study.

To understand the concept and convert it into an algorithm, we need to follow some steps. ie. we will first find the approach , then we will convert this approach into actionable steps and then convert it to algorithm. So what is the approach.

We know that we need to find the value of weight(w), so we initialize the value of w to 1 and we try to check the condition, if it is not equal, we try the random next value and we do the same process.

initialize w = 1

y = wx

y = 50 and x = 5 #first record

y = 50

wx = 1 * 5 =5

50- 5 = 45 #actually we subtracted, we need 0 as an answer to be equal

so y and x are not same here

Here what we actually did was subtraction. The value we get after subtraction is called error. We need 0 as error to conclude and finialize our answer, as we get an error, we initialise next random number and do the same process

lets take w = 3

y = 50 and x = 5

y- wx = 0

50–3*5 = 50–15 = 35

As we advances , the error is getting decreased and the error is getting closer and closer to 0. This means that the approach we are using right and as we increase the weight the error goes down. The overall motto of ML and DL(Deep Learning) is to complete this formula. If we put w=10 , we will get the error as zero.

w = 10

y- wx = 50- 10*5 = 0

Assume that we get the weight by randomly initializing the values, here we got the weight/ co-efficient = 10. This is the approach internally the algorithm is doing. But we have only tried the weight in one record and we can’t conclude the weight to be 10 yet.

If we apply the weight to other records we get the y to be exact but in real world data, we will never get the exact value of get don’t get error 0 as a result, because there may be so many exceptional cases that , someone can learn about 4 hours and get 90 marks, so our motto is not always to get the exact result, but to minimise the error.

So we find a weight where everyone fit and with minimum error, We can’t change the factual data but we can change the weight. ie. we can reiterate over all the record and adjust the weight. That is how the core works.

In some datasets we have some exceptions, and Machine Learning exceptions are called Outliers. They won’t fit to our criteria and these outliers are neglected by the algorithm.

This is how the Regression algorithm working behind the scene, we don’t want to learn how to write the algorithm and all, we are using the precreated algorithm using this concept.

In real world we never get 100% result or confidence score, if we get 80% to 90% confidence score, it is considered to be a good model.

It is time for some practical on real data. We have been provided with a real data, click here to see the data. This is a data having one feature, that is Year of experience and target is salary.

Let’t train the model in this dataset

import pandas

from sklearn.linear_model import LinearRegression

db = pandas.read_csv(‘SalaryData’)

x = db[‘YearsExperience’].values.reshape(30,1)

y = db[‘Salary’]

model =LinearRegression()

model.fit(x, y)

model.coef_

array([9449.96232146])

so the model is trained and we get the co-efficient 9449.96232146. There may be chance that someone with 0 years could apply. But if we take the example we can’t give them 0 sallery, that would be appropriate and we we do the prediction using the trained model we will see what result we get.

model.predict([[0]])

array([25792.20019867])

How can this be possible? Because in real world, we will give some salary for the fresher too, like a bare minimum, like we must be biased towards them. In ML also we use the same concept called bias. So our actual formula is changed

y = c+wx

So here the c will be constant or bias in ML. In our previous example of demo data also this bias was there and on that data prediction was 100% as it is an unrealistic data, the bias was 0. The algorithm uses the same way that used to find the weight in finding bias also.

Docker

So, I have written an introduction to docker and containerization in this ariticle, visit the artice and install the docker and come back to this article.

Hope you all have docker in your system insalled, To know wheather the docker is properly installed or not, you can use the command:

docker -v

to check the installed version, if you get responded with any version number, we are good to go.

As we know docker is a containarization technology, it containerises the operating system. So to boot an OS, we need an image. The image of docker containers are available in hub.docker.com and we can go to the website and find the OS image we need and they will give the command to pull the OS to the local system.

we can see the command

docker pull centos

This will download the OS image and will be saved on our local system, if we need to boot this OS image, we can run the command:

docker run -it centos

What this command will do is that, it will boot the OS in less than a second and will give us a interactive terminal so ,we can do our operations and things we do on a normal OS.

docker ps

This commad will show all the currently active OS in docker and if you want to see all the previous stoped OS’s we can use the command

docker ps -a

To attach an OS, we can use the command:

docker attach <docker container name>

This will reattach the OS and give you the terminal for that.

We can do all the machine learning practical on top of docker and get the same result. So that’s for today guys, read the next article.

Cheers!

Sarath Kumar R S

--

--

Sarath Kumar R S

Highly enthusiastic individual who is constantly looking solutions by using technology.