SVM系列(五)SVM python 应用实例(二) iris+ 西瓜数据

本文通过SVM对Iris数据进行多种核函数的分类并可视化,接着利用西瓜数据集进行汽车测评的分类。在汽车数据中,经过数据清洗处理不平衡的数据,使用RBF核函数训练模型,获得了0.97的高精度。
摘要由CSDN通过智能技术生成

iris数据分类以及可视化

1.多种核函数分类

from sklearn.svm import SVC
import matplotlib.pyplot as plt
%matplotlib inline
from sklearn import datasets
import numpy as np
from sklearn.model_selection import train_test_split
iris = datasets.load_iris()
X = iris.data[:,:2]
y = iris.target
X_train,X_test, y_train,y_test = train_test_split(X,y,test_size = 0.2)
estimators = {}
'''    
It must be one of 'linear', 'poly', 'rbf', 'sigmoid', 'precomputed' or a callable.
    '''
estimators['linear'] = SVC(kernel='linear',C= 0.1)
estimators['rbf'] = SVC(kernel='rbf')
estimators['poly'] = SVC(kernel='poly',degree= 4)
estimators['sigmoid'] = SVC(kernel='sigmoid')

2.可视化 


i = 0
plt.figure(figsize=(2*5,2*5))
for key,val in estimators.items():
    val.fit(X_train,y_train)
    score = val.score(X_test,y_test)
    d_ =  val.predict(np.c_[X1.ravel(),Y1.ravel()])
    ax = plt.subplot(2,2,i+1)
    plt.contourf(X1,Y1,d_.reshape(100,100),cmap = plt.cm.PuOr_r,alpha = 0.8)
    plt.contour(X1,Y1,d_.reshape(100,100))
    #plt.scatter(X_train[:,0],X_train[:,1],s=30,c = y_train ,cmap = plt.cm.Paired,edgecolors = 'k')
    plt.scatt
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lee_Yu_Rui

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值