SVC

import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
# This is used for out dataset
# dataset at : https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html#sklearn.datasets.load_breast_cancer
from sklearn.datasets import load_breast_cancer
dataCancer = load_breast_cancer()
data = dataCancer.data[:,0:2]  # 原数据集有30个特征,我们这里只取2个特征target = dataCancer.target  
# 获得‘标签’
model = svm.SVC(kernel = 'linear', C=10000)model.fit(data,target)
# plots the pointsplt.scatter(data[:,0],data[:,1],c=target,s=30,cmap=plt.cm.prism)
# Creates the axis bounds for the gridaxis = plt.gca()x_limit = axis.get_xlim()y_limit = axis.get_ylim()

# Creates a grid to evaluate modelx = np.linspace(x_limit[0],x_limit[1],50)  # 生成等差数列y = np.linspace(y_limit[0],y_limit[1],50)X,Y = np.meshgrid(x,y)  # 生成坐标矩阵xy = np.c_[X.ravel(),Y.ravel()]# .c_左右 矩阵相加 / .r_ 上下矩阵相加# .ravel() //将多维数组转换为一维数组# 这里xy 就相当于 [ [x1,y1],[x2,y2],[x3,y3]...]print(x)
# Creates the decision line for the data points,# use model.predict if you are classifying more than two.decision_line = model.decision_function(xy).reshape(Y.shape)
# decision_function(): 计算样本点到分割超平面的 函数距离# ??????????????  xy???
# Plot the decision line and the marginsaxis.contour(X,Y,decision_line,colors = 'k',levels=[0],linestyles=['-'])
# Shows the support vectors that determine the desision line.axis.scatter(model.support_vectors_[:,0],model.support_vectors_[:,1],s=100,             linewidth=1,facecolors='none',edgecolors='k')plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值