Title: Find Support Vectors
Slug: find_support_vectors
Summary: How to find support vectors in Scikit-Learn
Date: 2017-09-22 12:00
Category: Machine Learning
Tags: Support Vector Machines
Authors: Chris Albon
In [1]:
# Load libraries
from sklearn.svm import SVC
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
import numpy as np
In [2]:
#Load data with only two classes
iris = datasets.load_iris()
X = iris.data[:100,:]
y = iris.target[:100]
In [3]:
# Standarize features
scaler = StandardScaler()
X_std = scaler.fit_transform(X)
In [4]:
# Create support vector classifier object
svc = SVC(kernel='linear', random_state=0)
# Train classifier
model = svc.fit(X_std, y)
In [5]:
# View support vectors
model.support_vectors_
Out[5]:
In [6]:
# View indices of support vectors
model.support_
Out[6]:
In [7]:
# View number of support vectors for each class
model.n_support_
Out[7]: