机器学习--------SVM
#SVM的使用
(结合具体代码说明,代码参考邹博老师的代码)
1、使用numpy中的loadtxt读入数据文件
data:鸢尾花数据
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
读取:

:path路径
:dtype读取类型
:delimiter分隔符
:converters- A dictionary mapping column number to a function that will parse the column string into the desired value. E.g., if column 0 is a date string: ``converters = {0: datestr2num}``. Converters can also be used to provide a default value for missing data (but see also genfromtxt): ``converters = {3: lambda s: float(s.strip() or 0)}``.
:Default None.
*data
[[5.1, 3.5, 1.4, 0.2, 0. ], [4.9, 3. , 1.4, 0.2, 0. ], [4.7, 3.2, 1.3, 0.2, 0. ], [4.6, 3.1, 1.5, 0.2, 0. ],[5. , 3.6, 1.4, 0.2, 0. ]]
2、数据分训练测试集
*split用法
def split(ary,indices_or_sections,axis = 0):
'''
Split an array into multiple sub-arrays.
'''
Parameters-------------
ary : ndarray---Array to be divided into sub-arrays.
indices_or_sections---int or 1-D array If `indices_or_sections` is an integer, N, the array will be divided into N equal arrays along `axis`. If such a split is not possible,
an error is raised.
If `indices_or_sections` is a 1-D array of sorted integers, the entries indicate where along `axis` the array is split. For example,``[2, 3]`` would, for ``axis=0``, result in
ary[:2]
ary[2:3]
ary[3:]
If an index exceeds the dimension of the array along `axis`,an empty sub-array is returned correspondingly.
axis:int,optional---The axis along which to split,default is 0.
0按列分割,1按行分割
Return:sub-array:list of ndarrays
A list of sub-arrays
example:

3、训练SVM

kernel='linear'时,为线性核,C越大分类效果越好,但有可能出现过拟合;
kernel='rbf'时,为高斯核,gamma越小,分类界面越连续;gamma越大,分类界面越分散,分类效果越好(训练集),但是有可能会过拟合。
decision_function_shape='ovr'时(one v rest),即一个类别与其他类别进行划分;
decision_function_shape='ovo'时(one v one),即将类别两两之间进行划分,用二分类的方法模拟多分类的结果。
*准确率计算方式

机器学习--------SVM的更多相关文章
- 文本分类学习 (五) 机器学习SVM的前奏-特征提取(卡方检验续集)
前言: 上一篇比较详细的介绍了卡方检验和卡方分布.这篇我们就实际操刀,找到一些训练集,正所谓纸上得来终觉浅,绝知此事要躬行.然而我在躬行的时候,发现了卡方检验对于文本分类来说应该把公式再变形一般,那样 ...
- 机器学习——SVM详解(标准形式,对偶形式,Kernel及Soft Margin)
(写在前面:机器学习入行快2年了,多多少少用过一些算法,但由于敲公式太过浪费时间,所以一直搁置了开一个机器学习系列的博客.但是现在毕竟是电子化的时代,也不可能每时每刻都带着自己的记事本.如果可以掏出手 ...
- 程序员训练机器学习 SVM算法分享
http://www.csdn.net/article/2012-12-28/2813275-Support-Vector-Machine 摘要:支持向量机(SVM)已经成为一种非常受欢迎的算法.本文 ...
- [机器学习]SVM原理
SVM是机器学习中神一般的存在,虽然自深度学习以来有被拉下神坛的趋势,但不得不说SVM在这个领域有着举足轻重的地位.本文从Hard SVM 到 Dual Hard SVM再引进Kernel Trick ...
- [机器学习] SVM——Hinge与Kernel
Support Vector Machine [学习.内化]--讲出来才是真的听懂了,分享在这里也给后面的小伙伴点帮助. learn from: https://www.youtube.com/wat ...
- 小刘的机器学习---SVM
前言: 这是一篇记录小刘学习机器学习过程的随笔. 正文: 支持向量机(SVM)是一组用于分类, 回归和异常值检测的监督学习方法. 在分类问题中,SVM就是要找到一个同时离各个类别尽可能远的决策边界即最 ...
- 机器学习—SVM
一.原理部分: 依然是图片~ 二.sklearn实现: import pandas as pd import numpy as np import matplotlib.pyplot as plt i ...
- 机器学习——SVM讲解
支持向量机(Support Vector Machine) SVM是一类按监督学习方式对数据进行二元分类的广义线性分类器,决策边界是对学习样本求解的最大边距超平面.只需要知道,SVM是一个有监督的分类 ...
- 机器学习——SVM
整理自: https://blog.csdn.net/woaidapaopao/article/details/77806273?locationnum=9&fps=1 带核的SVM为什么能分 ...
随机推荐
- LOJ #6509. 「雅礼集训 2018 Day7」C
神仙题 LOJ #6509 题意 给定一棵树,点权为0/1,每次随机一个点(可能和之前所在点相同)走到该点并将其点权异或上1 求期望的移动距离使得所有点点权相同 题解 根本不会解方程 容易发现如果一个 ...
- ubuntu 安装 lamp
链接: http://www.cnblogs.com/CheeseZH/p/4694135.html
- word20170108逛景点 Sightseeing有用的词和句子
有用的词: sights and attractions: 景点 ticket booth: 售票处 will call ticket: 网络售票 guided tour: 带导游的游览 audio ...
- 读spring源码(二)-XmlBeanDefinitionReader-解析BeanDefinition
上次说到ApplicationContext加载BeanDefinition时会创建一个XmlBeanDefinitionReader,将XML解析.BeanDefinition加载委托给XmlBea ...
- Mac下的unity兼容问题,打开项目提示错误:!GetPersistentManager().IsStreamLoaded(assetPath)
安装unity成功之后,打开unity提示如下 那么打开的unity项目很有可能出现找不到资源的错误. 在检查一下你的Mac宗卷格式,如果是APFS格式的话,基本都会不兼容低版本的32位unity应用 ...
- js数据结构与算法——队列
<script> //创建一个队列 function Queue(){ let items = []; //向队尾添加一个新的项 this.enqueue = function(eleme ...
- 饮冰三年-人工智能-Python-25 Django admin
简介:一个关于后台数据库管理的工具 1:创建一个新的项目 2:设置models,并通过命令生成数据库表 from django.db import models class Book(models.M ...
- leetcode python两数之和返回索引
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target ...
- sql server 实现split功能 行转列
--實現split功能的函數create function [dbo].[func_split]( @SourceSql varchar(max), @StrSeprate varchar(10))r ...
- 微信域名检测的C#实现
背景:最近公司的公众号域名被封了,原因是公司网站被黑后上传了一个不符合微信规范的网页.所以...就进入了微信域名解封的流程. 百度微信域名解封发现很多微信域名检测的网站,还有Api:但是本人做微信公 ...