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(, columns=iris.feature_names)
y = pd.DataFrame(, columns=["flower_types"])

clf = SVC(), y["flower_types"])

Add in the ScienceOps part:

Import the yhat module:

from yhat import Yhat, YhatModel, preprocess

class MySVC(YhatModel):
    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([:1])
#         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", "")
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([:1])
yh.predict("SupportVectorClassifier", test)

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


results matching ""

    No results matching ""