Simplified Way To Get Started With Machine Learning Plus Integration With Docker

Ayush Bhat
5 min readMay 26, 2021

--

Hi Guys!! In this article we will learn first how to create Machine Learning Model and then we will run that model inside container using Containerization Tool, Docker.

Before starting let’s thought why we need to learn Machine Learning?

We need O.S. to run a program and if our program needs some data then O.S. will retrieve it from local hard disk. We need to note here that machines are much faster than humans. But how we can provide the intelligence to machine? Let’s consider an example in a company HR department wants to analyze how much we have to pay to a Computer Science Engineer based on his/her experience. For solving these thing the teams collected data from various source and used various platforms. The data that is being collected is called Historical Data or we can say it a Dataset in ML world. Below is the figure of Dataset.

In the above dataset we have collected various observations. So now if a candidate comes with an experience of 2.5 yrs how much we have to pay? First we will go to dataset and look for 2.5 yrs of experience and it’s corresponding salary. But in our dataset we don’t have any observation with this experience. Now question raises how much we should pay? If we apply some Math's here we will see that Salary = (Experience X Some-Number) .

But we as humans are slow in doing calculations we will take more time whereas this calculation will be done by machine in some seconds. But how are we going to predict how much we should pay that candidate?

Answer for this is Machine Learning but how ? For this we have to follow three steps:

  1. Tell the machine which formula to use
  2. Train that model
  3. We can use that model for prediction.

Let’s little bit focus on the second point Training the Model . As to better understand this let’s take an example we humans are very intelligent as we learn from our past experiences like when we start learning math it’s not like this we became perfect on the day one. On first day we learn what are numbers then we learn how to add and subtract then we learn division and multiplication and so on. It takes us years to be comfortable with the numbers. But how is that possible, how are we learning and creating such amazing things in world? The base of this is we learn, repeat and then again learn. We solve multiple problems of math and finally we achieve the approach to solve problems. This quality we have to provide to machine that is to make machine to learn from it’s own experiences. This is what we call Machine Learning.

Which language we choose to learn ML?

Python is one of the most famous language used in ML world. As it is easy to learn and implement. It is a cross platform language means we can run same python code in Windows, Linux or Mac.

What is Model?

Consider the same example if we somehow create a pattern in machine so that it will predict how much to pay candidate with 2.5 yrs of experience. Then this is called Machine Model. Who will create this model? Our Python Program will handle it.

For this tasks some prerequisites are:

  1. Anaconda Distribution, it comes with Python and lots of data science libraries.
  2. Virtualization Tool like Vmware, Virtual Box
  3. RHEL 8
  4. Docker installed on RHEL 8

Base O.S. I am using Windows and will have anaconda installed there. When we will go for integrating Machine Learning Model with Docker then we need RHEL 8 that I have installed on Virtual Box.

What is plan?

  1. Launch Jupyter Notebook.
  2. Have dataset in your workspace.
  3. Write the code and test it.

Link for the GitHub here you will find the code .

https://github.com/AyushBhat822/machine-learning.git

Now we will integrate the code with Docker

  1. Launch VM
  2. Install Docker
  3. Start docker services

4. Launch the centos container of latest version as it comes with yum pre-configured.

Inside the container

1. Install python

2. Install scikit-learn library

3. Install Pandas Library

4. Install git

5. Clone the repo from GitHub and get the dataset

6. Write the ML code

7. Run the ML code

Step 1 :

Step 2 :

Step 3:

Step 4:

Step 5:

Step 6:

Step 7:

It was the demonstration of Simple Linear Regression Model. Why is it called so? As in this dataset we were trying to predict the value of Salary which was dependent on Experience.

Thanks for reading this article. That’s all.

--

--

Ayush Bhat
Ayush Bhat

Written by Ayush Bhat

AWS SAA-C02 | Certified Kubernetes Administrator | Linux Foundation Certified Sysadmin | Ex294 RedHat Certified Engineer

No responses yet