sklearn中SVM调参说明

写在前面

之前只停留在理论上,没有实际沉下心去调参,实际去做了后,发现调参是个大工程(玄学)。于是这篇来总结一下sklearn中svm的参数说明以及调参经验。方便以后查询和回忆。

常用核函数

1.linear核函数:

K(xi,xj)=xTixjK(xi,xj)=xiTxj



2.polynomial核函数:

K(xi,xj)=(γxTixj+r)d,d>1K(xi,xj)=(γxiTxj+r)d,d>1


3.RBF核函数(高斯核函数):

K(xi,xj)=exp(γ||xixj||2),γ>0K(xi,xj)=exp(−γ||xi−xj||2),γ>0


4.sigmoid核函数:

K(xi,xj)=tanh(γxTixj+r),γ>0,r<0K(xi,xj)=tanh(γxiTxj+r),γ>0,r<0

 

sklearn svm 相关参数的官方说明

Parameters:
C : float, optional (default=1.0). Penalty parameter C of the error term.
kernel : string, optional (default=’rbf’). Specifies the kernel type to be used in the algorithm. It must be one of ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’ or a callable. If none is given, ‘rbf’ will be used. If a callable is given it is used to pre-compute the kernel matrix from data matrices; that matrix should be an array of shape (n_samples, n_samples).
degree : int, optional (default=3). Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.
gamma : float, optional (default=’auto’). Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’. If gamma is ‘auto’ then 1/n_features will be used instead.
coef0 : float, optional (default=0.0). Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’.
probability : boolean, optional (default=False). Whether to enable probability estimates. This must be enabled prior to calling fit, and will slow down that method.
shrinking : boolean, optional (default=True). Whether to use the shrinking heuristic.
tol : float, optional (default=1e-3). Tolerance for stopping criterion.
cache_size : float, optional. Specify the size of the kernel cache (in MB).
class_weight : {dict, ‘balanced’}, optional. Set the parameter C of class i to class_weight[i]C for SVC. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classesnp.bincount(y))
verbose : bool, default: False. Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context.
max_iter : int, optional (default=-1). Hard limit on iterations within solver, or -1 for no limit.
decision_function_shape : ‘ovo’, ‘ovr’ or None, default=None. Whether to return a one-vs-rest (‘ovr’) decision function of shape (n_samples, n_classes) as all other classifiers, or the original one-vs-one (‘ovo’) decision function of libsvm which has shape (n_samples, n_classes * (n_classes - 1) / 2). The default of None will currently behave as ‘ovo’ for backward compatibility and raise a deprecation warning, but will change ‘ovr’ in 0.19.
New in version 0.17: decision_function_shape=’ovr’ is recommended.
Changed in version 0.17: Deprecated decision_function_shape=’ovo’ and None.
random_state : int seed, RandomState instance, or None (default). The seed of the pseudo random number generator to use when shuffling the data for probability estimation.

libsvm中参数说明

因为sklearn底层是调用libsvm的,因此sklearn中svm参数说明是可以直接参考libsvm中的。

1.linear核函数:

K(xi,xj)=xTixjK(xi,xj)=xiTxj


2.polynomial核函数:

K(xi,xj)=(γxTixj+r)d,d>1K(xi,xj)=(γxiTxj+r)d,d>1


3.RBF核函数(高斯核函数):

K(xi,xj)=exp(γ||xixj||2),γ>0K(xi,xj)=exp(−γ||xi−xj||2),γ>0


4.sigmoid核函数:

K(xi,xj)=tanh(γxTixj+r),γ>0,r<0K(xi,xj)=tanh(γxiTxj+r),γ>0,r<0

 

首先介绍下与核函数相对应的参数:
1)对于线性核函数,没有专门需要设置的参数
2)对于多项式核函数,有三个参数。-d用来设置多项式核函数的最高次项次数,也就是公式中的d,默认值是3。-g用来设置核函数中的gamma参数设置,也就是公式中的gamma,默认值是1/k(特征数)。-r用来设置核函数中的coef0,也就是公式中的第二个r,默认值是0。
3)对于RBF核函数,有一个参数。-g用来设置核函数中的gamma参数设置,也就是公式中gamma,默认值是1/k(k是特征数)。
4)对于sigmoid核函数,有两个参数。-g用来设置核函数中的gamma参数设置,也就是公式中gamma,默认值是1/k(k是特征数)。-r用来设置核函数中的coef0,也就是公式中的第二个r,默认值是0。

具体来说说rbf核函数中C和gamma :

SVM模型有两个非常重要的参数C与gamma。其中 C是惩罚系数,即对误差的宽容度。c越高,说明越不能容忍出现误差,容易过拟合。C越小,容易欠拟合。C过大或过小,泛化能力变差

gamma是选择RBF函数作为kernel后,该函数自带的一个参数。隐含地决定了数据映射到新的特征空间后的分布,gamma越大,支持向量越少,gamma值越小,支持向量越多。支持向量的个数影响训练与预测的速度。

这里面大家需要注意的就是gamma的物理意义,大家提到很多的RBF的幅宽,它会影响每个支持向量对应的高斯的作用范围,从而影响泛化性能。我的理解:如果gamma设的太大,方差会很小,方差很小的高斯分布长得又高又瘦, 会造成只会作用于支持向量样本附近,对于未知样本分类效果很差,存在训练准确率可以很高,(如果让方差无穷小,则理论上,高斯核的SVM可以拟合任何非线性数据,但容易过拟合)而测试准确率不高的可能,就是通常说的过训练;而如果设的过小,则会造成平滑效应太大,无法在训练集上得到特别高的准确率,也会影响测试集的准确率。

此外,可以明确的两个结论是:
结论1:样本数目少于特征维度并不一定会导致过拟合,这可以参考余凯老师的这句评论:
“这不是原因啊,呵呵。用RBF kernel, 系统的dimension实际上不超过样本数,与特征维数没有一个trivial的关系。”

结论2:RBF核应该可以得到与线性核相近的效果(按照理论,RBF核可以模拟线性核),可能好于线性核,也可能差于,但是,不应该相差太多。
当然,很多问题中,比如维度过高,或者样本海量的情况下,大家更倾向于用线性核,因为效果相当,但是在速度和模型大小方面,线性核会有更好的表现。


Reference
http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC
http://blog.csdn.net/lqhbupt/article/details/8610443
http://blog.csdn.net/lujiandong1/article/details/46386201

转载于:https://www.cnblogs.com/sddai/p/9696771.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/250611.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

TZOJ 3030 Courses(二分图匹配)

描述 Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the conditions: every stude…

vue --- configureWebpack模拟后台数据

初识 使用vue/cli搭建的项目可以在vue.config.js中,模拟一个后台(express写法)vue.config.js configureWebpack: {devServer: {// 模拟后台服务器 express写法before(app) {app.get(/api/login, function(req, res) {const { username, passwd } req.query;console.log(user…

TCP和UDP的优缺点及区别

转自&#xff1a;http://www.cnblogs.com/xiaomayizoe/p/5258754.html TCP的优点&#xff1a; 可靠&#xff0c;稳定 TCP的可靠体现在TCP在传递数据之前&#xff0c;会有三次握手来建立连接&#xff0c;而且在数据传递时&#xff0c;有确认、窗口、重传、拥塞控制机制&#xff…

e.getMessage 为空NULL

e.getMessage 为空NULL 在日常代码中免不了要try catch 切忌用try catch 去try 整个方法。 在对象操作之前尽量写上if 空判断。 反例&#xff1a; public void send(){ try{ 代码1&#xff1a;获取对象 代码2&#xff1a;操作代码1 代码3&#xff1a;操作代码2 代码4&#xff1…

Linux:客户端的实现

写了一个简单的服务器软件&#xff0c;但是没有写客户端。现在我将客户端实现了&#xff0c;其实昨天已经说了客户端的实现步骤了。 步骤&#xff1a; socket() 初始化 connet()链接 从标准输入读数据fgets() 传数据到服务器write() 读从服务器返回的数据read() 写数据到屏幕上…

vue --- http拦截,登录登出的逻辑设计

设计 在src目录下创建一个interceptor.js登录逻辑 设置拦截,在发起请求前,先判断用户是否登录(在本栗中,即是否能够在浏览器缓存中找到token). 登出逻辑 对服务端传过来的数据进行拦截,判断其状态码是否为401(未登录或token过期)清空浏览器缓存中的token重定向到登入页面 inte…

循环分支循环语句

# 三大结构 - 循环 - 分支 - 循环 . . .In [ ]:# 分支 - 分支的基本语法 - if 条件表达式&#xff1a; 语句1 语句2 语句3 ..... - 条件表达式就是计算结果必须是布尔值的表达式 - 表达式后面的冒号觉对不能少 - 注意 if 后面出现的语句&#xff0c;如果属于 if 语句块&…

HTTP 1.1与HTTP 1.0的比较

HTTP 1.1与HTTP 1.0的比较 一个WEB站点每天可能要接收到上百万的用户请求&#xff0c;为了提高系统的效率&#xff0c;HTTP 1.0规定浏览器与服务器只保持短暂的连接&#xff0c;浏览器的每次请求都需要与服务器建立一个TCP连接&#xff0c;服务器完成请求处理后立即断开TCP连接…

vue --- 前端代理发送http请求

后端 端口在3000使用jsonwebtoken和koa-jwt生成令牌并返回对’/api/userinfo’端口,先验证令牌是否通过,若通过返回数据 const Koa require(koa); const Router require(koa-router); // 生成令牌、验证令牌 const jwt require(jsonwebtoken); const jwtAuth require(koa…

python全栈开发-json和pickle模块(数据的序列化)

一、什么是序列化&#xff1f; 我们把对象(变量)从内存中变成可存储或传输的过程称之为序列化&#xff0c;在Python中叫pickling&#xff0c;在其他语言中也被称之为serialization&#xff0c;marshalling&#xff0c;flattening等等&#xff0c;都是一个意思。 为什么要序列化…

Gale-Shapley---婚姻匹配算法算法

原文链接&#xff1a;http://blog.csdn.net/cscmaker/article/details/8291131 &#xff08;一&#xff09;问题的引出&#xff1a; 有N男N女&#xff0c;每个人都按照他对异性的喜欢程度排名。现在需要写出一个算法安排这N个男的、N个女的结婚&#xff0c;要求两个人的婚姻应该…

大数据排重

注意用来排重的那个集合放到Set中&#xff0c; 可以是HashSet,或者其他Set(推荐使用HashSet),因为Set的contains效率更高&#xff0c;比list高很多 -----------------------------------------------------------------------------------------------------------------------…

大前端成长路径

路径(持续更新): 以下是我不同时期的博客链接可以和我的GitHub共同食用大家可以对比一下,我学的过程是缓慢型的… learning: 0个月 2018年09月开始接触前端,前端三剑客一个不知道一个不懂,于是对着W3C、菜鸟教程.一个一个敲开始啃红宝书《JavaScript高级程序设计》(第3版) le…

工具:meson+ninja(安装问题解决)

问题1&#xff1a;Python版本问题 报错信息&#xff1a; NOTICE: You are using Python 3.6 which is EOL. Starting with v0.62.0, Meson will require Python 3.7 or newer ubuntu 18默认的python3是3.6. 解决方案1&#xff1a;从源码安装python 3.7 wget https://www.pyth…

ListMapSet的操作和遍历

List&Map&Set的操作和遍历 Java的三大集合即&#xff1a;Set、List、Map。 Set&#xff1a;代表无序、不可重复的集合&#xff0c;常用的有HashSet&#xff08;哈希表实现&#xff09;、TreeSet&#xff08;红黑树实现&#xff09;&#xff1b;List&#xff1a;代表有序…

PHP中的魔术方法

概述 在面向对象编程中&#xff0c;PHP提供了一系列的魔术方法&#xff0c;这些魔术方法为编程提供了很多便利。PHP中的魔术方法通常以__(两个下划线)开始&#xff0c;并且不需要显示的调用而是由某种特定的条件出发。这篇文章简单总结了PHP中提供的魔术方法。 开始之前 在总结…

执行caffe的draw_net.py出现“GraphViz's executable dot not found”的解决方法

执行caffe的draw_net.py出现“GraphVizs executable "dot" not found”的解决方法 控制台输入如下指令画网络图&#xff1a;python ../../../python/draw_net.py train.prototxt train.png --rankdirTB &#xff08;Top-Bottom形式&#xff0c;纵向图&#xff09;pyt…

配置 --- vscode自定义代码段Snippets

目标 在vscode中输入vbs-vue 然后产生一个自己想要的模板 写好模板 在线上写好模板传送门: https://snippet-generator.app/ 1是标题,对应 2是前缀.对应在vue中使用的快捷键 vbs-vue3就是需要显示的代码段了 在vscode中配置 1.ctrlshiftp2.选择 Preferences: Configure U…

centos6安装composer

需要使用到curl&#xff0c;没有的话需要 yum -y install curl ###安装一、下载&#xff1a;curl -sS https://getcomposer.org/installer | php &#xff08;如果是网络原因多试几次&#xff09; 二、移动composer.phar移动到环境下让其变成可执行&#xff1a;mv compose…

透明图与元素居中

1,定位让元素居中 1. 透明度 opacity 默认值是1 不透明 0是全透明转载于:https://www.cnblogs.com/Shinigami/p/9709382.html