Machine Learning operations over a Docker Container

Akshay Gupta
2 min readMay 30, 2021

In this Blog, We will train and run a machine learning model over a docker container with the least amount of resources and time using containerization.

So, This task is performed step by step:

  1. Download and install docker into the base OS
  2. Then Download and image from docker hub
  3. Launch a container
  4. Download and install python3 in container and also install pandas, numpy and sklearn library using pip
  5. Write the code to train the model
  6. Now Run the model

Step 1 > Install the Docker using command:

yum install docker-ce -nobest -y

To check docker is running or not.

systemctl status docker

Step 2 > run a command to pull image of CentOS (or as per your preference) from the docker hub over the internet:

docker pull centos: latest

Step 3 > Now, we will launch our docker container using the downloaded image.

docker run -it — name Task1 centos-latest

Step 4 > Then, We will install python3 in container .

yum install python3

and, also install pandas library,

pip3 install pandas

numpy library,

pip3 install numpy

and sklearn library.

pip3 install sklearn

Step 5 > Now, we create the code of python to train the model.

vi Salary_Predictor.py

Code >

import pandas
import numpy
db = pandas.read_csv(‘Salary.csv’)
y = db[“Salary”]
x = db[‘YearsExperience’]
x = x.values
x = x.values.reshape(-1,1)
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit( x, y)
years = int(input(“Enter your Years Experience to predict the Salary”))
Salary_approx = model.predict([[ years ]])
print(Salary_approx)

Step 6 > Now, At Last we will run the code:

python3 Salary_Predictor.py

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Akshay Gupta
Akshay Gupta

No responses yet

Write a response