print(__doc__)
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.datasets import make_blobs
# we create 40 separable points
X, y = make_blobs(n_samples=40, centers=2, random_state=6)
# fit the model, don't regularize for illustration purposes
clf = svm.SVC(kernel='linear', C=1000)
clf.fit(X, y)
plt.scatter(X[:, 0], X[:, 1], c=y, s=30, cmap=plt.cm.Paired)
# plot the decision function
ax = plt.gca()
xlim = ax.get_xlim()
ylim = ax.get_ylim()
# create grid to evaluate model
xx = np.linspace(xlim[0], xlim[1], 30)
yy = np.linspace(ylim[0], ylim[1], 30)
YY, XX = np.meshgrid(yy, xx)
xy = np.vstack([XX.ravel(), YY.ravel()]).T
Z = clf.decision_function(xy).reshape(XX.shape)
# plot decision boundary and margins
ax.contour(XX, YY, Z, colors='k', levels=[-1, 0, 1], alpha=0.5,
linestyles=['--', '-', '--'])
# plot support vectors
ax.scatter(clf.support_vectors_[:, 0], clf.support_vectors_[:, 1], s=100,
linewidth=1, facecolors='none', edgecolors='k')
plt.show()
참조 : scikit-learn.org/stable/auto_examples/svm/plot_separating_hyperplane.html#sphx-glr-auto-examples-svm-plot-separating-hyperplane-py
SVM: Maximum margin separating hyperplane — scikit-learn 0.23.2 documentation
Note Click here to download the full example code or to run this example in your browser via Binder SVM: Maximum margin separating hyperplane Plot the maximum margin separating hyperplane within a two-class separable dataset using a Support Vector Machine
scikit-learn.org
'머신러닝 > 알고리즘' 카테고리의 다른 글
5-2-1. k-means 실습 (0) | 2020.09.12 |
---|---|
5-2. k-means (k-평균 알고리즘) (0) | 2020.09.12 |
5-1. SVM (Support Vector Machine) (0) | 2020.09.12 |
4-1-2. 타이타닉 생존자 예측 - 의사결정나무 정확도 (0) | 2020.09.11 |
4-1-1. 타이타닉 생존자 예측 - 의사결정나무 (0) | 2020.09.11 |