This repo contains files to code that deploys an API endpoint for a user to predict Median value of owner-occupied homes in $1000s (MEDV). The model was trained on the Boston Housing Dataset.
A notebook with steps about building, training and running the model is provided with steps shown.
Boston_Housing_Model_Building.ipynb
Please open the notebook shown above and run through the steps.
The directory structure is provided below.
.
├── Boston_Housing_Model_Building.ipynb
├── Dockerfile
├── HousingData_test.csv
├── HousingData_train.csv
├── LICENSE
├── README.md
├── knn_imputer.joblib
├── requirements.txt
├── server.py
├── templates
│ ├── base.html
│ ├── index.html
│ └── output.html
└── xg_regressor.joblib
Listed below are different ways to build and run the system. There are a total of 3 ways to build and run the system. They are:
- Build from the git repo.
- Build using docker image.
-
Clone the project Git repo.
foo@bar:~$ git clone https://github.com/likith11/Boston-Housing-DataSet-Predictor.git
-
Move into the project directory.
foo@bar:~$ cd Boston-Housing-DataSet-Predictor
-
Create a virtual environment and activate it.
foo@bar:~$ python3 -m venv foo@bar:~$ source venv/bin/activate
-
Install requirements from requirements.txt
(venv) foo@bar:~$ pip install -r requirements.txt
NOTE : Steps to run shown below in Steps To RUN the web server in To run locally using py file section:
- Pull image from docker hub.
foo@bar:~$ docker pull likithponnanna/boston-housing-predictor
- Run the image that was pulled. Below port 5000 is mapped between the external and docker container.
foo@bar:~$ docker run -p 5000:5000 boston-housing-predictor
NOTE : Steps to run also shown below in Steps To RUN the web server in To run the docker image section.
- To build the docker image using the dockerfile locally run the following command before initiating docker run.
foo@bar:~$ git clone https://github.com/likith11/Boston-Housing-DataSet-Predictor.git foo@bar:~$ cd Boston-Housing-DataSet-Predictor foo@bar:~$ docker build -t boston-housing-predictor .
- Run the docker image with port specified.
foo@bar:~$ docker run -p 5000:5000 boston-housing-predictor
NOTE : Steps to run also shown below in Steps To RUN the web server in To run the docker image section.
- To run locally.
- To run the docker image.
(venv) foo@bar:~$ python server.py
Run the docker image with port specified.
foo@bar:~$ docker run -p 5000:5000 boston-housing-predictor
There are 2 ways of using the web deployment.
- Using GUI
- Using API call
1.) Using GUI:
- Navigate to http://0.0.0.0:5000/ or http://localhost:5000/ (Replace port number if its a different port on your machine. The default port above is 5000).
- Two text fields with pre-filled test data along with a blue Process button is displayed.
- Change the input field to the required test input.
- Click on _Process__
- A new screen with Translucent alert box is shown with the corresponding MEDV predicted.
- Click on Retry? button to go back to the main screen and repeat the process.
2.)Using API call:
- API end point is deployed at http://0.0.0.0:5000/api/predict where POST request is accepted.
- The API accepts text inputs in the JSON format shown below
{ "CRIM": 9.39063, "ZN": 0.0, "INDUS": 18.1, "CHAS": 0, "NOX": 0.74, "RM": 5.627, "AGE": 93.9, "DIS": 1.8172, "RAD": 24.0, "TAX": 666.0, "PTRATIO": 20.2, "B": 396.9, "LSTAT": 22.88 }
- An example curl command is
curl -d '{ "CRIM" : 9.39063, "ZN" : 0.0, "INDUS" : 18.1, "CHAS" : 0, "NOX" : 0.740, "RM" : 5.627, "AGE" : 93.9, "DIS" : 1.8172, "RAD" : 24.0, "TAX" : 666.0, "PTRATIO":20.2, "B" : 396.90, "LSTAT" : 22.880 }' -H 'Content-Type: application/json' http://0.0.0.0:5000/api/predict
- An API response json is returned with the the predicted MEDV value.