Created
February 27, 2018 20:40
-
-
Save socratesk/b881a75e8ed1d7ff8c42465f0ae53b3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import Flask class from the flask module | |
from flask import Flask, request | |
import numpy as np | |
import pickle | |
# Create Flask object to run | |
app = Flask(__name__) | |
@app.route('/') | |
def home(): | |
return "Hi, Welcome to Flask!!" | |
@app.route('/predict') | |
def predict(): | |
# Get values from browser | |
sepLen = request.args['sepal_length'] | |
sepWid = request.args['sepal_width'] | |
petLen = request.args['petal_length'] | |
petWid = request.args['petal_width'] | |
testData = np.array([sepLen, sepWid, petLen, petWid]).reshape(1,4) | |
class_prediced = int(svmIrisModel.predict(testData)[0]) | |
output = "Predicted Iris Class: " + str(class_prediced) | |
return (output) | |
# Load the pre-trained and persisted SVM model | |
# Note: The model will be loaded only once at the start of the server | |
def load_model(): | |
global svmIrisModel | |
svmIrisFile = open('models/SVMModel.pckl', 'rb') | |
svmIrisModel = pickle.load(svmIrisFile) | |
svmIrisFile.close() | |
if __name__ == "__main__": | |
print("**Starting Server...") | |
# Call function that loads Model | |
load_model() | |
# Run Server | |
app.run() |
From the Server log, I see that you are trying to determine the probability using "_probA".
To determine probability, instantiate the classifier object as below:
svmIrisModel = sklearn.svm.SVC(probability=True)
Seems there is a typo too. It should be "svmIrisModel.predict_proba(testData[0])". In the above log, I see "probA_".
Hope this helps.
Thanks Socratesk.
I was trying to create a flask API app for an Iris dataset model and I had this error that has left me almost depressed and stucked for some days now.
Please kindly look into the codes and help me see what I'm doing wrong.
If need be I can push the codes to repo.
Thank you for your help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi socratesk,
I tried running your work on here and i was faced with an error
please kindly look into it and let me know what i'm doing wrong.
thank you