#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的更多相关文章

  1. 文本分类学习 (五) 机器学习SVM的前奏-特征提取(卡方检验续集)

    前言: 上一篇比较详细的介绍了卡方检验和卡方分布.这篇我们就实际操刀,找到一些训练集,正所谓纸上得来终觉浅,绝知此事要躬行.然而我在躬行的时候,发现了卡方检验对于文本分类来说应该把公式再变形一般,那样 ...

  2. 机器学习——SVM详解(标准形式,对偶形式,Kernel及Soft Margin)

    (写在前面:机器学习入行快2年了,多多少少用过一些算法,但由于敲公式太过浪费时间,所以一直搁置了开一个机器学习系列的博客.但是现在毕竟是电子化的时代,也不可能每时每刻都带着自己的记事本.如果可以掏出手 ...

  3. 程序员训练机器学习 SVM算法分享

    http://www.csdn.net/article/2012-12-28/2813275-Support-Vector-Machine 摘要:支持向量机(SVM)已经成为一种非常受欢迎的算法.本文 ...

  4. [机器学习]SVM原理

    SVM是机器学习中神一般的存在,虽然自深度学习以来有被拉下神坛的趋势,但不得不说SVM在这个领域有着举足轻重的地位.本文从Hard SVM 到 Dual Hard SVM再引进Kernel Trick ...

  5. [机器学习] SVM——Hinge与Kernel

    Support Vector Machine [学习.内化]--讲出来才是真的听懂了,分享在这里也给后面的小伙伴点帮助. learn from: https://www.youtube.com/wat ...

  6. 小刘的机器学习---SVM

    前言: 这是一篇记录小刘学习机器学习过程的随笔. 正文: 支持向量机(SVM)是一组用于分类, 回归和异常值检测的监督学习方法. 在分类问题中,SVM就是要找到一个同时离各个类别尽可能远的决策边界即最 ...

  7. 机器学习—SVM

    一.原理部分: 依然是图片~ 二.sklearn实现: import pandas as pd import numpy as np import matplotlib.pyplot as plt i ...

  8. 机器学习——SVM讲解

    支持向量机(Support Vector Machine) SVM是一类按监督学习方式对数据进行二元分类的广义线性分类器,决策边界是对学习样本求解的最大边距超平面.只需要知道,SVM是一个有监督的分类 ...

  9. 机器学习——SVM

    整理自: https://blog.csdn.net/woaidapaopao/article/details/77806273?locationnum=9&fps=1 带核的SVM为什么能分 ...

随机推荐

  1. Android logcat lines missing原因分析

    当出现类似如下错误日志时: 2019-04-14 17:51:14.506 10189-10189/com.ss.android.ex.parent D/GGK: no WonderfulVideo ...

  2. C# - 设计模式 - 模板模式

    模板模式 问题场景 咖啡和茶派生于抽象类饮料,咖啡和茶都具有烧水的方法,所以可以将烧水的方法提取到抽象类饮料中去实现,而咖啡具有一个向杯子加咖啡粉的方法,茶具有一个向杯子加茶叶的方法,看起来两个方法是 ...

  3. android 给view添加阴影

    1.方法一: 使用 CardView 布局 <android.support.v7.widget.CardView xmlns:android="http://schemas.andr ...

  4. c++17 代码你能看懂吗?

    ------------------------------------------------------------------------------ #include <vector&g ...

  5. [JavaScript]ECMA-6 箭头函数

    概述 箭头函数的作用是为Js提供一种函数的简写方法,箭头函数作用域内不包含this, arguments, super, or new.target,并且不能用于对象的构造函数: 基本语法 [(][p ...

  6. ActiveMQ与spring整合

    第一步:引用相关的jar包 <dependency> <groupId>org.springframework</groupId> <artifactId&g ...

  7. BaiduMap路程计算

    #BaiduMap路程计算def getDistance(deslat,deslng,originlat,originlng): url='http://api.map.baidu.com/direc ...

  8. oracle INS-13001 环境不满足最低要求

    使用windows10等系统安装oracle 11g等版本的数据库时,经常会发现开始安装时弹出[INS-13001 环境不满足最低要求]的提示,此时可以点击[是]继续安装. 也可以点击[否]结束安装, ...

  9. iOS开发之获取当前展示的VC

    /** 递归查找当前显示的VC*/ + (UIViewController *)recursiveFindCurrentShowViewControllerFromViewController:(UI ...

  10. Vue过滤器使用

    格式(一个过滤器):{{ 'msg' | filterA }} (多个过滤器):{{ 'msg' | filterA | filterB }} window.onload =function(){ / ...