优化网站性能监测,石排镇做网站,做交网站,网页制做写在前面 之前只停留在理论上#xff0c;没有实际沉下心去调参#xff0c;实际去做了后#xff0c;发现调参是个大工程#xff08;玄学#xff09;。于是这篇来总结一下sklearn中svm的参数说明以及调参经验。方便以后查询和回忆。 常用核函数 1.linear核函数: K(xi,xj)xTi… 写在前面 之前只停留在理论上没有实际沉下心去调参实际去做了后发现调参是个大工程玄学。于是这篇来总结一下sklearn中svm的参数说明以及调参经验。方便以后查询和回忆。 常用核函数 1.linear核函数: K(xi,xj)xTixjK(xi,xj)xiTxj 2.polynomial核函数: K(xi,xj)(γxTixjr)d,d1K(xi,xj)(γxiTxjr)d,d1 3.RBF核函数高斯核函数: K(xi,xj)exp(−γ||xi−xj||2),γ0K(xi,xj)exp(−γ||xi−xj||2),γ0 4.sigmoid核函数: K(xi,xj)tanh(γxTixjr),γ0,r0K(xi,xj)tanh(γxiTxjr),γ0,r0 sklearn svm 相关参数的官方说明 Parameters:C : float, optional (default1.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 (default3). 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 (default0.0). Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’.probability : boolean, optional (defaultFalse). Whether to enable probability estimates. This must be enabled prior to calling fit, and will slow down that method.shrinking : boolean, optional (defaultTrue). Whether to use the shrinking heuristic.tol : float, optional (default1e-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, defaultNone. 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)(γxTixjr)d,d1K(xi,xj)(γxiTxjr)d,d1 3.RBF核函数高斯核函数: K(xi,xj)exp(−γ||xi−xj||2),γ0K(xi,xj)exp(−γ||xi−xj||2),γ0 4.sigmoid核函数: K(xi,xj)tanh(γxTixjr),γ0,r0K(xi,xj)tanh(γxiTxjr),γ0,r0 首先介绍下与核函数相对应的参数1对于线性核函数没有专门需要设置的参数2对于多项式核函数有三个参数。-d用来设置多项式核函数的最高次项次数也就是公式中的d默认值是3。-g用来设置核函数中的gamma参数设置也就是公式中的gamma默认值是1/k特征数。-r用来设置核函数中的coef0也就是公式中的第二个r默认值是0。3对于RBF核函数有一个参数。-g用来设置核函数中的gamma参数设置也就是公式中gamma默认值是1/kk是特征数。4对于sigmoid核函数有两个参数。-g用来设置核函数中的gamma参数设置也就是公式中gamma默认值是1/kk是特征数。-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的关系。” 结论2RBF核应该可以得到与线性核相近的效果按照理论RBF核可以模拟线性核可能好于线性核也可能差于但是不应该相差太多。当然很多问题中比如维度过高或者样本海量的情况下大家更倾向于用线性核因为效果相当但是在速度和模型大小方面线性核会有更好的表现。 Referencehttp://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVChttp://blog.csdn.net/lqhbupt/article/details/8610443http://blog.csdn.net/lujiandong1/article/details/46386201 转载于:https://www.cnblogs.com/sddai/p/9696771.html