python高斯核函数_科学网—Python_机器学习_总结7:使用核SVM解决非线性问题 - 李军的博文...

1、训练数据集

home.php?mod=attachment&filename=image.png&id=242308

2、不同gamma值训练结果

home.php?mod=attachment&filename=image.png&id=242311

home.php?mod=attachment&filename=image.png&id=242313

程序代码如下:from sklearn.svm import SVC

import matplotlib.pyplot as plt

import numpy as np

from plot_decision_regions import plot_decision_regions

#利用随机噪声得到一个异或数据集

np.random.seed(0)

X_xor = np.random.randn(200, 2)

y_xor = np.logical_xor(X_xor[:,0] >0 , X_xor[:,1]>0)

y_xor = np.where(y_xor, 1, -1)

plt.scatter(X_xor[y_xor==1, 0], X_xor[y_xor==1, 1], c='b', marker='x', label='l')

plt.scatter(X_xor[y_xor==-1, 0], X_xor[y_xor==-1, 1], c='r', marker='s', label='l')

plt.ylim(-3.0)

plt.legend()

plt.show()

#利用高斯核函数进行分类

svm = SVC(kernel='rbf', random_state=0, gamma=0.10, C=10.0)

svm.fit(X_xor, y_xor)

plot_decision_regions(X_xor, y_xor, classifier = svm)

plt.legend(loc='upper left')

plt.title('gamma = 0.1')

plt.show()

#

svm = SVC(kernel='rbf', random_state=0, gamma=1.0, C=10.0)

svm.fit(X_xor, y_xor)

plot_decision_regions(X_xor, y_xor, classifier = svm)

plt.legend(loc='upper left')

plt.title('gamma = 1.0')

plt.show()

补充:

#参考《Python 机器学习》,作者:Sebastian Raschaka, 机械工业出版社;

转载本文请联系原作者获取授权,同时请注明本文来自李军科学网博客。

链接地址:http://blog.sciencenet.cn/blog-3377553-1130717.html

上一篇:Python_机器学习_总结6:线性SVM分类Iris

下一篇:Python_机器学习_总结8:决策树

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值