-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
56 lines (45 loc) · 1.37 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, request, jsonify
from flask.logging import create_logger
import logging
import pandas as pd
import joblib
from sklearn.preprocessing import StandardScaler
app = Flask(__name__)
LOG = create_logger(app)
LOG.setLevel(logging.INFO)
def scale(payload):
"""Scales Payload"""
LOG.info(f"Scaling Payload: {payload}")
scaler = StandardScaler().fit(payload)
scaled_adhoc_predict = scaler.transform(payload)
return scaled_adhoc_predict
@app.route("/")
def home():
html = f"<h3>Sklearn Prediction Home</h3>"
return html.format(format)
@app.route("/predict", methods=['POST'])
def predict():
"""Performs an sklearn prediction
input looks like (check prediction_payload.json):
{
"CHAS":{
"0":0
},
"RM":{
"0":6.575
},
...
result looks like:
{ "prediction": [ 20.35373177134412 ] }
"""
json_payload = request.json
LOG.info(f"JSON payload: {json_payload}")
inference_payload = pd.DataFrame(json_payload)
LOG.info(f"inference payload DataFrame: {inference_payload}")
scaled_payload = scale(inference_payload)
prediction = list(clf.predict(scaled_payload))
LOG.info(f"prediction {prediction}")
return jsonify({'prediction': prediction})
if __name__ == "__main__":
clf = joblib.load("boston_housing_prediction.joblib")
app.run(host='0.0.0.0', port=5000)