学习网址:http://scikit-learn.org/stable/modules/svm.html

SVM案例代码:

# -*- coding: utf-8 -*-
__author__ = 'Jason.F'#http://scikit-learn.org/stable/modules/svm.htmlimport numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2]  # we only take the first two features. We could# avoid this ugly slicing by using a two-dim dataset
y = iris.targeth = .02  # step size in the mesh# we create an instance of SVM and fit out data. We do not scale our
# data since we want to plot the support vectors
C = 1.0  # SVM regularization parameter
svc = svm.SVC(kernel='linear', C=C).fit(X, y)
rbf_svc = svm.SVC(kernel='rbf', gamma=0.7, C=C).fit(X, y)
poly_svc = svm.SVC(kernel='poly', degree=3, C=C).fit(X, y)
lin_svc = svm.LinearSVC(C=C).fit(X, y)# create a mesh to plot in
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),np.arange(y_min, y_max, h))# title for the plots
titles = ['SVC with linear kernel','LinearSVC (linear kernel)','SVC with RBF kernel','SVC with polynomial (degree 3) kernel']for i, clf in enumerate((svc, lin_svc, rbf_svc, poly_svc)):# Plot the decision boundary. For that, we will assign a color to each# point in the mesh [x_min, x_max]x[y_min, y_max].plt.subplot(2, 2, i + 1)plt.subplots_adjust(wspace=0.4, hspace=0.4)Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])# Put the result into a color plotZ = Z.reshape(xx.shape)plt.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8)# Plot also the training pointsplt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm)plt.xlabel('Sepal length')plt.ylabel('Sepal width')plt.xlim(xx.min(), xx.max())plt.ylim(yy.min(), yy.max())plt.xticks(())plt.yticks(())plt.title(titles[i])plt.show()

结果:

【Python学习系列九】Python机器学习库scikit-learn实现SVM案例相关推荐

  1. Python学习系列 -- 改善 Python 程序的 91 个建议

    转载自:https://zhuanlan.zhihu.com/p/32817459 自己写Python也有四五年了,一直是用自己的"强迫症"在维持自己代码的质量,除了Google的 ...

  2. 机器学习与Scikit Learn学习库

    摘要: 本文介绍机器学习相关的学习库Scikit Learn,包含其安装及具体识别手写体数字案例,适合机器学习初学者入门Scikit Learn. 在我科研的时候,机器学习(ML)是计算机科学领域中最 ...

  3. Python: 学习系列之七:模块、PIPY及Anaconda

    系列 Python: 学习系列之一:Python能做什么 Python: 学习系列之二:基础介绍(int/float/string/range/list/tuple/dict/set) Python: ...

  4. Python学习系列(六)(模块)

    Python学习系列(六)(模块) Python学习系列(五)(文件操作及其字典) 一,模块的基本介绍 1,import引入其他标准模块 标准库:Python标准安装包里的模块. 引入模块的几种方式: ...

  5. python sklearn 支持向量机_python机器学习库sklearn之支持向量机svm介绍

    python机器学习库sklearn之支持向量机svm介绍tcB太阳2平台注册|网站分类目录 python数据挖掘系列教程tcB太阳2平台注册|网站分类目录 这里只讲述sklearn中如何使用svm算 ...

  6. Python学习系列(五)(文件操作及其字典)

    Python学习系列(五)(文件操作及其字典) Python学习系列(四)(列表及其函数) 一.文件操作 1,读文件      在以'r'读模式打开文件以后可以调用read函数一次性将文件内容全部读出 ...

  7. python3.4学习笔记(九) Python GUI桌面应用开发工具选择

    python3.4学习笔记(九) Python GUI桌面应用开发工具选择 Python GUI开发工具选择 - WEB开发者 http://www.admin10000.com/document/9 ...

  8. 【python脚本系列】利用mido库解析midi文件

    [python脚本系列]利用mido库解析midi文件       Hallo大家好~~我是Lampard猿奋       昨天写了关于Midi数字化乐器接口的文章,介绍了midi是一组代表音乐参数( ...

  9. Python学习第九篇:zipfile 库操作压缩包

    ​ Python学习第九篇:zipfile 库操作压缩包 -- 活动地址:CSDN21天学习挑战赛 zipfile是python里用来做zip格式编码的压缩和解压缩的 zipfile里有两个非常常用的 ...

最新文章

  1. python3 http服务端响应源码
  2. python的celery的面试_python 面试
  3. 内存分析工具MAT的使用
  4. easyui表单网格列错位_《HTML5从入门到精通》——第3章 HTML表格与表单
  5. 【AI-1000问】为什么CNN中的卷积核半径都是奇数?
  6. SAP Spartacus 中的 Commands and queries
  7. todo项目开发_Facebook的TODO项目,巴西的Coursera,Drupal等
  8. MySQL的安装和基本操作
  9. stm32如何执行软复位_stm32f7软件复位 stm32f0 软件复位
  10. 什么才是真正的项目团队,我来告诉你需要做哪些
  11. 1.Linux系统编程入门
  12. 剑指 Offer 53 - II. 0~n-1中缺失的数字
  13. Nginx优化之虚拟主机
  14. Unity HDRP中解决抗锯齿问题
  15. USB UVC实战笔记第1篇—UVC设备枚举过程详细分析
  16. 鸿蒙和ios流畅对比,鸿蒙OS对比iOS,华为再次“超越”,流畅度大幅领先苹果!...
  17. 「自然语言处理(NLP)」入门系列(一)初识NLP
  18. 安装TOPAS RTion extension, 出现的问题及解决方法
  19. 哪位兄台能优化这条SQL语句,在线等,捉急!!!
  20. 基于springboot整合的rabbitmq

热门文章

  1. 基于pxe+dhcp+ks实现自动安装系统
  2. win2003 vps IIS6中添加站点并绑定域名的配置方法
  3. Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test)
  4. Entity Framework 学习结束语
  5. Android设备唯一性判断
  6. python软件加密、固定机器使用_如何用Python进行最常见的加密操作?(附最新400集Python教程)...
  7. 7.Mahout菩萨
  8. POJ 1321 棋盘问题 题解
  9. 注意链栈next指针的指向,与队列不同:
  10. Centos7 安装lnmp