Salary Predictor App Using Machine Learning and Docker
Hello Peeps !!
Hope you are safe and doing well :)
In this article, I am going to tell you how to create a salary predictor app using machine learning and Docker.
About the APP
It is a ML Based App that predicts salary on the basis of year of experience of the employee.
Task Overview
👉 Pull the Docker container image of CentOS image from DockerHub and create a new container
👉 Install the Python software on the top of docker container
👉 In Container, Create machine learning model
Task Description
First of all, let’s know what is Machine Learning and Docker
Machine Learning
Machine learning (ML) is the study of computer algorithms that improve automatically through experience and by the use of data. It is seen as a part of artificial intelligence. Machine learning algorithms build a model based on sample data, known as “training data”, in order to make predictions or decisions without being explicitly programmed to do so. Machine learning algorithms are used in a wide variety of applications, such as in medicine, email filtering, and computer vision, where it is difficult or unfeasible to develop conventional algorithms to perform the needed tasks.
Docker
Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.
Now, let’s start the task !!
First of all it is always good practice to create a separate Work-Space so that we can easily manage the things.
mkdir <folder_name>
cd <folder_name>
Here I created workspace with the name ML_Task1. I am going to put all the code in this directory only.
In this directory, I made a separate folder named dataset where I put the dataset and the machine learning code.
About the dataset
To train this model I used a dataset of 30 employees that contains two information, first their Years of Experience and second Salary.
Using this dataset, we have to create a Machine Learning Model that will predict salary on the basis of year of experience of the employee.
Now the interesting point is, here I am going to train this model inside a Docker Container.
So, here I will use Dockerfile to launch the container.
DockerFile
Docker can build images automatically by reading the instructions from a
Dockerfile
. ADockerfile
is a text document that contains all the commands a user could call on the command line to assemble an image. Usingdocker build
users can create an automated build that executes several command-line instructions in succession.
Here is my Dockerfile that I will use
From centos
RUN yum install python3 -y
RUN pip3 install pandas scikit-learn
COPY dataset/* /home/
CMD python3 /home/model_train.py
This Dockerfile, first pull the image of Centos from DockerHub Then It will install Python Interpreter as I have written machine learning code in Python so we will also need some python modules like “pandas” and “scikit-learn” so It will install them with pip3 command.
Then It will copy dataset and the ML code in the home directory of container, then train this model and launch the app.
Now let’s see the machine learning Code !! It is written is Python language.
Now, Build the image with Dockerfile so that we can use that image to launch a container.
docker build -t <image_name> <Path_of_Dockerfile>
Now, we just need to run a single command, and it will launch the os, train the model and start the app in just 1–2 second.
docker run -it <image_name>
Hope you find this article Helpful !!
Here is my Github Repository, If you have any doubt you can connect with me on LinkedIn.
Thanks for Reading :)