sklearn使用高斯核SVM显示支持向量
Posted starcrm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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显示支持向量的主要内容,如果未能解决你的问题,请参考以下文章