Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Prediction using a sklearn based model trained on Iris data set
import pickle
import random
iris_model = None
Species_class_map = None
def load_iris_model():
# load the pre-trained Iris model (here we are using a model
# pre-trained on Iris Classification using sklearn
global iris_model
global Species_class_map
iris_model = pickle.load(open('model.dat', 'rb'))
Species_class_map = {0:'Iris-setosa', 1:'Iris-versicolor', 2:'Iris-virginica'}
# Load models
print(("* Loading Iris model"))
def predict(self, params):
# take input pd data frame and return dictionary with classificaiton
X = params['X']
# Test feature
y_pred = iris_model.predict(X)
y_pred = [round(value) for value in y_pred]
prediction_result = {'Species': Species_class_map[y_pred[0]]}
return prediction_result
# if this is the main thread of execution first load the model and
# then start the server
# if __name__ == "__main__":
# print predict({'X': [[ 6.9, 3.2, 5.7, 2.3]]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.