import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.datasets import make_blobs
#先创建50个数据点,让它们分为两类
X,y=make_blobs(n_samples=50,centers=2,random_state=6)
#创建一个线性内核的支持向量机模型
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)
#建立图像坐标
ax=plt.gca()
xlim=ax.get_xlim()#(3.973450006529823, 10.807292643804692)
ylim=ax.get_ylim()#(-11.082326233912445, -1.0805946182292332)
#生成两个等差数列
xx=np.linspace(xlim[0],xlim[1],30)#linspace用于间隔采样
yy=np.linspace(ylim[0],ylim[1],30)
'''xx:[ 3.97345001 4.20909975 4.4447495 4.68039924 4.91604899 5.15169874
5.38734848 5.62299823 5.85864798 6.09429772 6.32994747 6.56559721
6.80124696 7.03689671 7.27254645 7.5081962 7.74384594 7.97949569
8.21514544 8.45079518 8.68644493 8.92209467 9.15774442 9.39339417
9.62904391 9.86469366 10.10034341 10.
支持向量机SVM【机器学习算法一线性内核vs高斯内核】
最新推荐文章于 2023-12-18 16:22:30 发布