How to make simple Machine Learining Model inside Docker Container

KARTHICK P
5 min readMay 30, 2021

--

SO first we move on to this topic ,

What is Machine Learning?

Machine Learning is a part of Artificial Intelligence (AI) where we can create our model by giving dataset to the system to learn/train by itself so that it can predict the answers like a human being.

I am docker container on Redhat 8 OS and it is running on my base OS Windows10 with the help of Virtualization.

Lets start working…

Before we create our Machine Learning model we need a data set , You guys can create your own dataset or You can get it from the Internet.

DOCKER INSTALLATION

First, we need to install docker through YUM after that we need to start our docker to create container and make it enable so it will be on start mode permanently.

PULLING THE CENTOS

after that we need to pull the CentOS images from the DockerHub,this command will download the latest version of CentOS.

LAUNCHING THE CENTOS

In this step we are going to launch the OS through run command and giving name to it for easy accessing . I am giving name as TASK1.

You can if our OS is running or not by using below command,

COPY THE CSV FILE FROM REDHAT8 TO CENTOS

Before copying the file from terminal to CentOS, we need to create one folder to store the CSV file like below,

In the above command I created a folder in CentOS called Summer Intern .

For coping the file we need to go to the base OS (Redhat8) you can use new tab from the file , and for copy the csv file,

docker cp <file_name>.csv CentOSname:/root/foldername/,

OPENING PYTHON TO CREATE OUR MODEL

before opening python we need to install it using the Yum command

and we need to Install some of the libraries for creating a Machine Learning model the common libraries are pandas, numpy, scikit-learn

CREATING THE MACHINE LEARING MODEL

For open a python use the python3 command and now import the pandas and read the csv file and store it in any variable I used ds,now you can see the dataset using that variable .

INDEPENDENT AND DEPENDENT VARIABLE

for train the model we have to store the independent/feature variable in x and dependent variable in Y in this dataset X is ‘ YearsExperience’ Y is ‘Salary’.

but X should be in a 2D array format but it is in 1D array (you can check using type(X))

here it is in pandasarray for changing it to 1D from 2D first we have to make this array as numpyarray by using (values method) and to make it is a 2D the method name is (reshape(: , :) method)

here I gave parameters for reshape method is (-1 ,1 ) we can use (30,1) also.

LINEAR REGRESSION

Here comes the main part of this topic Linear Regression ,

For Create a Liner Regression model we have to import scikit-learn here and for later accessing the model we can store it in a variable.

now we can train our data set to make our model so it can predict the answers ,for training our model the process is given below,

fit() function which helps our model to give experience from our dataset so our model trained and ready now it can predict things in our example it going to predict the salary which is not in the dataset.

the above example, it is predicted at 49417 so this model is giving 95% accuracy

So this is how you can create a machine learning model inside docker container Task done Successfully.

HOPE YOU GUYS LIKE IT .

— — — — — — — — — — — — THANK YOU— — — — — — — — — — — — — —

--

--

KARTHICK P
KARTHICK P

No responses yet