机器学习--------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为什么能分 ...
随机推荐
- 20164305 徐广皓 Exp4 恶意代码分析
实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals,systr ...
- CentOS7离线安装mysql5.7
下载mysql5.7,系统选择redhat,版本选择RHEL7,下载RPM Bundle后得到一个tar文件.这里得到文件mysql-5.7.25-1.el7.x86_64.rpm-bundle.ta ...
- Cocoapods安装 2018-11-01更新
2018-11-1 更新 pod install 报错 [!] Oh no, an error occurred. Cocoapods 需要更新 主要涉及2点内容 一.ruby 更新(V2.5.3 ...
- jmeter分布式测试教程和远程的代理机无法连接网络的问题解决方法
一.Jmeter分布式执行原理: 1.Jmeter分布式测试时,选择其中一台作为控制机(Controller),其它机器做为代理机(Agent). 2.执行时,Controller会把脚本发送到每台A ...
- HtmlWebpackPlugin用的html的ejs模板文件中如何使用条件判断
折腾: [已解决]给react-hot-boilerplate中的index.html换成用HtmlWebpackPlugin自动生成html 期间,已经有了思路了,但是不知道如何在ejs的html中 ...
- MySQL ERROR 1820 (HY000)
You must reset your password using ALTER USER statement before executing this statement报错处理 解决方式如下: ...
- git私有仓库与pycharm联合使用
文章目录 1 创建git私有仓库和pycharm的使用 1.1 克隆私有仓库到本地 1.2 使用pycharm打开 1.3 添加.gitignore文件 1.4 并将其添加到仓库 1.5 提交和推送 ...
- OpenCV-Python:霍夫变换
霍夫变换常用来在图像中提取直线和圆等几何形状.如下图: 我们下面来看看如何使用霍夫变换来检测直线.一条直线可以用数学表达式 y = mx + 或者 ρ = xcosθ + y sinθ表示(极坐标) ...
- C# Levenshtein计算字符串的相似度
static void Main(string[] args) { Levenshtein(@"今天天气不错", @"今天的天气不错啊"); Console.R ...
- 《物联网框架ServerSuperIO教程》- 23.动态数据接口增加缓存,提高数据输出到OPCServer和(实时)数据库的效率
22.1 概述及要解决的问题 设备驱动有DeviceDynamic接口,可以继承并增加新的实时数据属性,每次通讯完成后更新这些属性数据.原来是通过DeviceDynamic接口实体类反射的方式获 ...