机器学习sklearn之svm的实现

sklearn实现svm

from sklearn import svm#导出svm

x = [[2, 0], [1, 1], [2, 3]]#数据
y = [0, 0, 1]#标签
clf = svm.SVC(kernel = 'linear')#实例化
clf.fit(x, y)#拟合

print (clf)

# get support vectors
print (clf.support_vectors_)
# get indices of support vectors
print (clf.support_)
# get number of support vectors for each class
print (clf.n_support_)

print (clf.predict([[2,0]]))

在这里插入图片描述
拟合多个点,并得到超平面

import numpy as np
import pylab as pl
from sklearn import svm

np.random.seed(0)
# we create 40 separable points
X = np.r_[np.random.randn(20, 2) - [2, 2], np.random.randn(20, 2) + [2, 2]]
Y = [0]*20 +[1]*20

#fit the model
clf = svm.SVC(kernel='linear')
clf.fit(X, Y)

# get the separating hyperplane
w = clf.coef_[0]
a = -w[0]/w[1]
xx =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值