💁🏻‍♀️ Training ML model inside Docker Container🐋

✨ What is Machine Learning ?

✨ What is Docker ?

Task Description 📄

Let’s Begin🤩

Step1 : Install docker

Create a file “/etc/yum.repos.d/docker.repo”[docker]name=docker repo baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0
# Install docker
yum install docker-ce — nobest
# Start Docker service
systemctl start docker
# Enable Docker service
systemctl enable docker

Step2 : Pull centos image

docker pull centos:latest

Step3 : Launch a container

docker run -it --name <name_of_OS> centos:latest

Step3: Install required packages

# python
yum install python36
# installing required libraries for taskpip3 install pandas
pip3 install scikit-learn

Step4: Create a Docker image

docker commit <os_name> <image_name>:<version>

Step5 : Launch a container using that image

docker images

Step6: Copy the dataset

docker cp <location_in_localsystem>  <docker_os_name>:<location_in_docker_container>

Step6: Linear Regression Model

import pandas as pd
dataset = pd.read_csv('salarydata.csv')
X = dataset[['YearsExperience']]
y = dataset['Salary']
from sklearn.linear_model import LinearRegressionmodel = LinearRegression()model.fit(X,y)import joblib
joblib.dump(model, 'finalsalary2.pk1')

Step7: Model Created

Step8: Let’s Test !!

import joblib
model = joblib.load('finalsalary2.pk1')
yrsExp = float(input("Enter years of Experience : "))prediction = model.predict([[yrsExp]])print("Your Salary would be : ", prediction)

Thanks for Reading !! 🙌🏻😁📃

🔰 Keep Learning !! Keep Sharing !! 🔰

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store