E:\Anaconda\lib\site-packages\seaborn\_decorators.py:36: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
warnings.warn(
<AxesSubplot:>
from sklearn.svm import SVC
models=[SVC(kernel='linear',C=C)for C in(1,100)]
clfs=[model.fit(X,y.ravel())for model in models]
from matplotlib.colors import ListedColormap
defplot_decision_regions(X,y,classifier,test_idx=None,resolution=0.02):##简历颜色产生器和颜色绘图板
markers=('s','x','o','^','y')
colors=('red','blue','lightgreen','gray','cyan')
cmap=ListedColormap(colors[:len(np.unique(y))])##画出决策边界
x1_min,x1_max=X[:,0].min()*0.4,X[:,0].max()*1.4
x2_min,x2_max=X[:,1].min()*0.4,X[:,1].max()*1.4
xx1,xx2=np.meshgrid(np.arange(x1_min,x1_max,resolution),
np.arange(x2_min,x2_max,resolution))
z=classifier.predict(np.array([xx1.ravel(),xx2.ravel()]).T)
z=z.reshape(xx1.shape)
plt.contourf(xx1,xx2,z,alpha=0.2,cmap=cmap)
plt.xlim(0,5)
plt.ylim(1.5,5)#绘出样例
titles =['SVM Decision Boundary with C = {} (Example Dataset 1'.format(C)for C in[1,100]]for idx,title inenumerate(titles):
plt.scatter(x=X[y==idx,0],y=X[y==idx,1],
alpha=0.8,c=cmap(idx),
marker=markers[idx],label=idx)
plt.title(title)