Support Vector Classification

Here is a quick demo on how to deploy a Support Vector Classification model. Using the iris dataset, we'll try to predict the "flower species" based on "Sepal Length", "Sepal Width", "Petal Length", and "Petal Width".

Train your model:

Start by reading in our dataset:

import numpy as np
import pandas as pd
from sklearn.svm import SVC
from sklearn.datasets import load_iris

iris = load_iris()

X = pd.DataFrame(iris.data, columns=iris.feature_names)
y = pd.DataFrame(iris.target, columns=["flower_types"])

clf = SVC()
clf.fit(X, y["flower_types"])

Add in the ScienceOps part:

Import the yhat module:

from yhat import Yhat, YhatModel, preprocess

class MySVC(YhatModel):
    REQUIREMENTS=["numpy","pandas","scikit-learn"]
    def execute(self, data):
        prediction = clf.predict(pd.DataFrame(data))
        species = ['setosa', 'versicolor', 'virginica']
        result = [species[i] for i in prediction]
        return result

Test your model locally:

We recommend you test your model locally before deploying. After all, if it doesn't work locally, it won't work on ScienceOps!

test = pd.DataFrame(iris.data[:1])
MySVC().execute(test)
#         0
# 0  setosa

Deploy your model to ScienceOps:

The hard part is over. Now that we have our own model, it's time to deploy it! Create a connection to the ScienceOps server, then execute the deploy function.

yh = Yhat("USERNAME", "API_KEY", "https://sandbox.yhathq.com")
yh.deploy("SupportVectorClassifier", MySVC, globals())

Get Predictions via the REST API

Predictions from the model can be sent and received from the languages below in addition to others found on the REST API page.

test = pd.DataFrame(iris.data[:1])
yh.predict("SupportVectorClassifier", test)

For testing in the ScienceOps webpage, use the following data:

{
  "Sepal.Length":5.1,
  "Sepal.Width":3.5,
  "Petal.Length":1.4,
  "Petal.Width":0.2
}

results matching ""

    No results matching ""