This project is a Machine Learning project to predict housing price. The project has been build to a docker image which can easily be deployed as microservice in Kubernetes or Docker, using a YAML configuration file and/(or only) kubectl or docker command line utility respectively. Once deployed, the service exposes an endpoint which prediction calls can be made to.
To run the project, a Makefile has been added which contains the basic commands needed to setup the environment running. Note: it is reccommended that you run the project on a linux system or pull the image from docker hub to run in Kubernetes or Docker. You may as well follow the steps discussed later in this docs to build the docker image yourself.
Every commands listed here should be executed from the project's root directory
To run it as standalone app, you have to create a virtual environment by running the make command below:
For Linux
make setup
source ~/.devops/bin/activate
make install
python app.py
For Windows
python -m venv /.devops
/.devops/Scripts/activate
make install
python app.py
First you have to make sure that you have docker installed and running, then run the run_docker.sh bash script as below:
./run_docker.sh
If it throws a permission denied error, change the mode to executable using the command below
chmod +x run_docker.sh
You may have to do this as a root user for this to work.
First you have to make sure that Kubernetes and kubectl command line utility are installed and well configured. Then, run the command below:
./run_kubernetes.sh
The run_kubernetes.sh bash script will pull the existing image from docker hub, run the image in Kubernetes, list the pods available as a display of the success of the command, and finally forward a port to the host machine for previewing the result.
If you get a line saying, cannot forward port because pod is not running, status is pending, then you will have to wait for the pod to start running. Verify pod status using kubectl get pods
command. Once the pod is running, you can execute the command again, then go to the URL http://localhost:8000 to preview the result and to start making predictions.
Alternatively, you can use a YAML code to deploy the service in Kubernetes or Docker Swarm
Once the service running, then you can make a call to the endpoint with a payload containg the features data for which prediction is to be made. Example can be seen below:
curl -d '{
"CHAS":{
"0":0
},
"RM":{
"0":6.575
},
"TAX":{
"0":296.0
},
"PTRATIO":{
"0":15.3
},
"B":{
"0":396.9
},
"LSTAT":{
"0":4.98
}
}'\
-H "Content-Type: application/json" \
-X POST http://localhost:8000/predict
Alternatively, you could look into make_prediction.sh bash script and edit the feature values to make your predictions.
The Algorithm is a pretrained model. The model data and the pretrained model can be found in model_data directory. Inside app.py is a Flask app definition that service the prediction model on an endpoint when called.
This project integrates CircleCI for CI/CD. The CircleCI configuration file, config.yml can be found inside .circleci directory. That's the file CircleCI looks into for instructions on what to do in the Pipeline.
As you may have notice, at the topmost level of this docs, just after the title is a CircleCI badge, which displays the current status of the Pipeline build. Here it is again.