SVM支持向量机(二)13

该博客详细介绍了SVM支持向量机的建模过程,从线性核函数到非线性的poly、rbf和sigmoid核函数的应用。此外,还探讨了SVM在回归问题中的应用,并通过实例展示了如何使用不同核函数进行天猫双十一销量数据的预测。
摘要由CSDN通过智能技术生成

1  导包

import numpy as np
from sklearn import datasets
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt

2  加载数据

X,y=datasets.load_wine(return_X_y=True)
display(X.shape)
输出:
(178, 13)
x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2)
display(x_train.shape,y_train.shape)
输出:
(142, 13)
(142,)

3  建模

3.1  线性:linear

svc=SVC(kernel='linear')
svc.fit(x_train,y_train)
yred=svc.predict(x_test)
score=accuracy_score(yred,y_test)
display('使用linear核函数得分:',score)
输出:
'使用linear核函数得分:'
0.9444444444444444
svc.coef_
输出:
array([[ 0.68238177,  0.59090752,  1.17127315, -0.21150042,  0.0081547 ,
        -0.01397723,  0.2235816 ,  0.22634936, -0.41167559,  0.47889006,
        -0.16003878,  0.50632237,  0.00469413],
       [ 0.08796641,  0.13272108,  0.04146849, -0.07352927,  0.00631995,
         0.28416506,  0.43334105,  0.00655127,  0.18678886, -0.26506095,
         0.03456889,  0.29852352,  0.00403859],
       [-0.6507222 , -0.33430121, -0.36136551, -0.02392738, -0.02279356,
         0.37705139,  1.19788242,  0.28111838,  0.54743024, -0.61747287,
         0.43714574,  0.94564
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值