Skip to content

Instantly share code, notes, and snippets.

@socratesk
Created February 23, 2018 16:49
Show Gist options
  • Save socratesk/383e0a0d6f448847aeb83ab712db2d61 to your computer and use it in GitHub Desktop.
Save socratesk/383e0a0d6f448847aeb83ab712db2d61 to your computer and use it in GitHub Desktop.
# This is a sample model to demonstrate how a Machine Learning model
# can be implemented in Production as a REST API and how it can be consumed
# Import libraries and packages
from sklearn import svm, datasets
import pickle
import numpy as np
# Load Sample data
iris = datasets.load_iris()
# Split loaded data into independent and target features
X = iris.data
y = iris.target
# Train Support Vector Machine (SVM) model with all data
svmModel = svm.SVC(kernel='poly', degree=3, C=1.0).fit(X, y)
# Persist model so that it can be used by different consumers
svmFile = open('SVMModel.pckl', 'wb')
pickle.dump(svmModel, svmFile)
svmFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment