-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMV_Flask_API.py
37 lines (27 loc) · 975 Bytes
/
SMV_Flask_API.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
from flask import Flask, request, jsonify
import joblib
import numpy as np
import sklearn
app = Flask(__name__)
model = joblib.load('SVM_Salary.pkl')
sc_X = joblib.load('sc_X.pkl')
sc_Y = joblib.load('sc_Y.pkl')
@app.route('/')
def home():
return "Welcome to the SVR Model Prediction API!"
@app.route('/predict', methods=['POST'])
def predict():
# Get the data from the POST request
data = request.json
print("Received data:", data)
features = np.array([[data['feature']]])
# Preprocess the data
features_transformed = sc_X.transform(features)
# Make prediction
prediction = model.predict(features_transformed)
# Inverse transform to original scale
prediction_original_scale = sc_Y.inverse_transform(prediction.reshape(-1, 1))
# Return the result as a JSON response
return jsonify({'prediction': prediction_original_scale[0, 0]})
if __name__ == '__main__':
app.run(debug=True)