Running an ML Model Inside a Container…

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:
- 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

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>

🔰 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:

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:


🔰 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..


🔰 Now , let’s test by some prediction:

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…👋👋👋