turicreate.svm_classifier.SVMClassifier¶

class turicreate.svm_classifier.SVMClassifier(model_proxy)

Support Vector Machines can be used to predict binary target variable using several feature variables.

The SVMClassifier model predicts a binary target variable given one or more feature variables. In an SVM model, the examples are represented as points in space, mapped so that the examples from the two classes being classified are divided by linear separator.

Given a set of features $$x_i$$, and a label $$y_i \in \{0,1\}$$, SVM minimizes the loss function:

$f_i(\theta) = \max(1 - \theta^T x, 0)$

An intercept term is added by appending a column of 1’s to the features. Regularization is often required to prevent over fitting by penalizing models with extreme parameter values. The composite objective being optimized for is the following:

$\min_{\theta} \sum_{i = 1}^{n} f_i(\theta) + \lambda ||\theta||^{2}_{2}$

where $$\lambda$$ is the penalty parameter.

This model cannot be constructed directly. Instead, use turicreate.svm_classifier.create() to create an instance of this model. Additional details on parameter options and code samples are available in the documentation for the create function.

Examples

# Load the data (From an S3 bucket)
>>> import turicreate as tc
>>> data =  tc.SFrame('https://static.turi.com/datasets/regression/houses.csv')

# Make sure the target is binary 0/1
>>> data['is_expensive'] = data['price'] > 30000

# Make a logistic regression model
>>> model = tc.svm_classifier.create(data, target='is_expensive'
, features=['bath', 'bedroom', 'size'])

# Extract the coefficients
>>> coefficients = model.coefficients # an SFrame

# Make predictions (as margins, or class)
>>> predictions = model.progressredict(data)    # Predicts 0/1
>>> predictions = model.progressredict(data, output_type='margin')

# Evaluate the model
>>> results = model.progressvaluate(data)               # a dictionary


Methods

 SVMClassifier.classify(dataset[, …]) Return a classification, for each example in the dataset, using the trained SVM model. SVMClassifier.evaluate(dataset[, metric, …]) Evaluate the model by making predictions of target values and comparing these to actual values. SVMClassifier.export_coreml(filename) Export the model in Core ML format. SVMClassifier.predict(dataset[, …]) Return predictions for dataset, using the trained logistic regression model. SVMClassifier.save(location) Save the model. SVMClassifier.summary([output]) Print a summary of the model.