Machine Learning Model on Container
What are containers?
Containers are a form of operating system virtualization. A single container might be used to run anything from a small microservice or software process to a larger application. Inside a container are all the necessary executables, binary code, libraries, and configuration files. Compared to server or machine virtualization approaches, however, containers do not contain operating system images. This makes them more lightweight and portable, with significantly less overhead. In larger application deployments, multiple containers may be deployed as one or more container clusters.
Benefits of containers
- Less overhead
Containers require less system resources than traditional or hardware virtual machine environments because they don’t include operating system images. - Increased portability
Applications running in containers can be deployed easily to multiple different operating systems and hardware platforms. - More consistent operation
DevOps teams know applications in containers will run the same, regardless of where they are deployed. - Greater efficiency
Containers allow applications to be more rapidly deployed, patched, or scaled. - Better application development
Containers support agile and DevOps efforts to accelerate development, test, and production cycles.
Task :
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 you need to copy/create machine learning model which you have created in jupyter notebook
Let’s Get Started
- We need to pull container image of CentOS from DockerHub. We can do that with the help of the following command:
docker pull centos:version
2. Now we need to run the container and copy the dataset & the python program in the container. To do that, we can use the following command:
docker run -it -v /dir_in_baseos:/dir_in_container --name task-1 cetos
Now we have copied the directory and successfully launched our container.
3. So to be able to create and use our machine learning model, we need to set up the environment first.
We need to install python first in our container. We can use “yum” to install it
yum install python3
This will install the python 3 successfully for us
But we still can’t create our model yet as we still need to install the required python libraries. We need the following libraries:
=> numpy
=> pandas
=> scikit-learn
We can use pip3 to install them
pip3 install numpy pandas scikit-learn
Now our environment is set to create and use our Machine Learning model
4. Create the model
This is the final step of our task.
- First we need to go inside the directory where we copied our dataset and program.
- Now we can start with training our model and predicting the salary on the basis of year of experience
As we can see… it successfully predicted the salary.
Thank You for reading this article
My LinkedIn: Rohan Khandelwal