Deploying Simple Machine Learning Model inside Docker Container

Deploying Simple Machine Learning Model inside Docker Container

Task Description 📄

👉 Pull the Docker container image of CentOS image from Docker Hub and Create a new container

👉 Install the Python software on the top of the docker container

👉 In Container you need to copy/create a machine learning model

1. Install docker in base OS:

  • Already installed in my case.
No alt text provided for this image


2. Pulling the Centos image from docker hub

No alt text provided for this image

Pull the image using docker pull centos command.

3. Launching a Docker container using the centos image

No alt text provided for this image

By using docker run -it --name mlindocker centos command we have launched docker container with centos image and container name as mlindocker.

4. Copying the dataset into the container

No alt text provided for this image

5. Installing python3 software inside the docker container

No alt text provided for this image

6. Installing the necessary libraries (numpy, pandas, scikit-learn) using pip3

pip3 install numpy

pip3 install pandas

pip3 install scikit-learn

No alt text provided for this image

7. Writing the ML code

import pandas as pd
dataset = pd.read_csv('salarydata.csv')

X = dataset[['YearsExperience']]
y = dataset['Salary']
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X,y)
import joblib
joblib.dump(model, 'finalsalary2.pk1')

8. Now we are set to run the model file

No alt text provided for this image

As we can see when we enter the number of years of experience the ML model is giving the expected salary.

We have successfully deployed the ML model inside Docker Container



To view or add a comment, sign in

Explore content categories