Running an ML Model Inside a Container…

Vamsi Mathala
3 min readMay 30, 2021

Objective of the story:
👉 Pull the Docker container image of CentOS image from DockerHub and run a new container.
👉 Install the Python software and necessary libraries on the top of docker container.
👉 In Container you need to copy/create machine learning model.

🔰 Configuration of Docker:

  1. Create a yum repo so that we can download the yum software from internet as follows:

2. Download Docker software : yum install docker-ce --no-best

Already Installed in my case..

3. Start the Docker Services: systemctl start docker

🔰 Pull Centos image from the docker Hub

syntax: docker pull <image_name>

🔰 Launch a new container using centos image.

Syntax: docker run -it --name <container_name> <image_name>

Container launched.

🔰 Install Python3 software and required libraries for the ML model in the container.
◼ yum install python3 -y
◼ pip3 install pandas
◼ pip3 install sklearn

🔰 Now Let’s Create our ML model:

Firstly ,I created a workspace for codes and all where initially i copied my dataset of Salary and years of experience which we can further use to predict ones salary based on their experience which is based on Simple Linear Regression.

Here is the simple code that creates my model:

create_model.py

And in the above code, we can observe that the model is saved so that we further directly load our model instead running and creating the model always.

🔰 Now ,let’s create the model by executing the above code:

Model Created..
Model Saved..

🔰 Now, as a final step Let’s test our model:

For this testing I have created a simple python file where I loaded the model and make it user friendly by asking the input from command line as follows..

predict_salary.py

🔰 Now , let’s test by some prediction:

..Final Output..

So that’s all for the task guys…This task is mainly meant to show how can we use containers in the world of Machine Learning..

And I know , In this task i mentioned mostly the technical part but for some more blogs including detail explanation from the start are posted and will be done on my LinkedIn…So connect me on my Linkedin Profile for more details and queries….😇😇😇

Thanks for reading…👋👋👋

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

Vamsi Mathala
Vamsi Mathala

Written by Vamsi Mathala

CSE undergraduate, highly interested to work on industry technologies.

No responses yet

Write a response