sklearn使用高斯核SVM显示支持向量

import graphviz
import mglearn
from mpl_toolkits.mplot3d import Axes3D
from sklearn.datasets import load_breast_cancer, make_blobs
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeClassifier, export_graphviz
from IPython.display import display
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mt
import pandas as pd

X, y = mglearn.tools.make_handcrafted_dataset()
svm = SVC(kernel='rbf', C=100, gamma=0.1).fit(X, y)
mglearn.plots.plot_2d_separator(svm, X, eps=.5)
mglearn.discrete_scatter(X[:, 0], X[:, 1], y)
# plot support vectors
sv = svm.support_vectors_
print(sv)
# class labels of support vectors are given by the sign of the dual coefficients
sv_labels = svm.dual_coef_.ravel() > 0
mglearn.discrete_scatter(sv[:, 0], sv[:, 1], sv_labels, s=15, markeredgewidth=3)
plt.xlabel("Feature 0")
plt.ylabel("Feature 1")
plt.show()

sklearn使用高斯核SVM显示支持向量_第1张图片

你可能感兴趣的:(sklearn使用高斯核SVM显示支持向量)