Training and Testing Machine Learning Model inside Docker Container

docker containers provide quick environment setup to deploy any product hence we are using this to train our model and then predict by providing some dummy inputs…

Machine Learning:

Docker :

Fig 1. dataset.csv File

ML-Salary-Estimator-Python Code:

Fig 2. ML-CODE File
  • Loading of Data
  • Fetching relevant independent features for finding prediction pattern\formula
  • Loading Linear Regression function as we have linear data in hand (dataset.csv)
  • Fitting the value of predictor (x) and predict (y)
  • This whole training we are doing here can be just done once and after that we can save the model output weight and bais to load and use. (Suggestion)
  • At the end it would ask user about entering the product or exit with ‘Y’ or ’N’ keys
  • Then Prediction function would work as user input the ‘Year of Experience’ of new joining employ to estimate salary
  • We have options to continue working or ‘exit’ when work is done.

Pre-requisite :

Let’s Discuss the Problem Statement:

  • We have to pull Docker Container image of Centos from hub.docker.com and further create a container from that image.
  • Inside that Launched Container
    1. Install Python3 software
    2. Install python modules scikit-learn, numpy and pandas using “pip3”
  • Copy the ML code that we have created for Salary Prediction inside the container and then deploy it. We can do this in 2 ways:
    1. by “docker cp” command to copy code directly from base OS.
    2. by “git clone” as we pushed the code and data to GitHub repository for further use.
  1. You can See I have my docker.service running in Rhel 8 Linux Machine
Fig 3. docker daemon active
# docker pull centos:7
Fig 4. Centos Images present in my System
Fig 5. Lunched esti-con container
# yum install python3 -y
Fig 5. Installed python3 software
# pip3 install scikit-learn numpy pandas
Fig 6. installed all the required library
# docker cp <source_path> esti-con:<destination_path>
Fig 7. We have copied both dataset and code to the docker container
Fig 8. Execution of our ML Program

--

--

Platform Engineer | Kubernetes | Docker | Terraform | Helm | AWS | Azure | Groovy | Jenkins | Git, GitHub | Sonar | NMAP and other Scan and Monitoring tool

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
Akanksha Singh

Platform Engineer | Kubernetes | Docker | Terraform | Helm | AWS | Azure | Groovy | Jenkins | Git, GitHub | Sonar | NMAP and other Scan and Monitoring tool