sklearn中的svm参数介绍
来源:互联网 发布:linux udp 端口 编辑:程序博客网 时间:2024/05/18 23:56
svm是sklearn中一个关于支持向量机的包,比较常用,在使用过程中若是不熟悉各个参数的意义,总以默认参数进行机器学习,则不能做到最优化使用SVM,这就是一个较为遗憾的事情了。为了加深理解和方便调用,根据现有理解,结合官方文档,对其中的参数做一些记录,方便自己时常温习,也给阅读者进行一些粗浅的介绍,如果有理解错误的地方,希望阅读者能够指出。
以svm中的支持向量分类SVC作为介绍,所有参数如下:
class sklearn.svm.SVC( C=1.0, kernel='rbf', degree=3, gamma='auto', coef0=0.0, shrinking=True, probability=False, tol=0.001, cache_size=200, class_weight=None, verbose=False, max_iter=-1, decision_function_shape='ovr', random_state=None)
具体每个参数的使用方法介绍如下:
C : float, optional (default=1.0) 误差项的惩罚参数,一般取值为10的n次幂,如10的-5次幂,10的-4次幂。。。。10的0次幂,10,1000,1000,在python中可以使用pow(10,n) n=-5~inf C越大,相当于惩罚松弛变量,希望松弛变量接近0,即对误分类的惩罚增大,趋向于对训练集全分对的情况,这样会出现训练集测试时准确率很高,但泛化能力弱。 C值小,对误分类的惩罚减小,容错能力增强,泛化能力较强。
kernel : string, optional (default=’rbf’) svc中指定的kernel类型。 可以是: ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’ 或者自己指定。 默认使用‘rbf’ 。
degree : int, optional (default=3) 当指定kernel为 ‘poly’时,表示选择的多项式的最高次数,默认为三次多项式。 若指定kernel不是‘poly’,则忽略,即该参数只对‘poly’有作用。
gamma : float, optional (default=’auto’) 当kernel为‘rbf’, ‘poly’或‘sigmoid’时的kernel系数。 如果不设置,默认为 ‘auto’ ,此时,kernel系数设置为:1/n_features
coef0 : float, optional (default=0.0) kernel函数的常数项。 只有在 kernel为‘poly’或‘sigmoid’时有效,默认为0。
probability : boolean, optional (default=False) 是否采用概率估计。 必须在fit()方法前使用,该方法的使用会降低运算速度,默认为False。
shrinking : boolean, optional (default=True) 如果能预知哪些变量对应着支持向量,则只要在这些样本上训练就够了,其他样本可不予考虑,这不影响训练结果,但降低了问题的规模并有助于迅速求解。进一步,如果能预知哪些变量在边界上(即a=C),则这些变量可保持不动,只对其他变量进行优化,从而使问题的规模更小,训练时间大大降低。这就是Shrinking技术。 Shrinking技术基于这样一个事实:支持向量只占训练样本的少部分,并且大多数支持向量的拉格朗日乘子等于C。
tol : float, optional (default=1e-3) 误差项达到指定值时则停止训练,默认为1e-3,即0.001。
cache_size : float, optional 指定内核缓存的大小,默认为200M。
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_classes * np.bincount(y))
verbose : bool, default: False 是否启用详细输出。 多线程时可能不会如预期的那样工作。默认为False。
max_iter : int, optional (default=-1) 强制设置最大迭代次数。 默认设置为-1,表示无穷大迭代次数。 Hard limit on iterations within solver, or -1 for no limit.
decision_function_shape : ‘ovo’, ‘ovr’, default=’ovr’ ##这个用法也不是很理解## 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). Changed in version 0.19: decision_function_shape is ‘ovr’ by default. 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, RandomState instance or None, optional (default=None) 伪随机数使用数据。
一些属性介绍:
Attributes: support_ : array-like, shape = [n_SV] Indices of support vectors.support_vectors_ : array-like, shape = [n_SV, n_features] Support vectors.n_support_ : array-like, dtype=int32, shape = [n_class] Number of support vectors for each class.dual_coef_ : array, shape = [n_class-1, n_SV] Coefficients of the support vector in the decision function. For multiclass, coefficient for all 1-vs-1 classifiers. The layout of the coefficients in the multiclass case is somewhat non-trivial. See the section about multi-class classification in the SVM section of the User Guide for details.coef_ : array, shape = [n_class-1, n_features] Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel. coef_ is a readonly property derived from dual_coef_ and support_vectors_.intercept_ : array, shape = [n_class * (n_class-1) / 2] Constants in decision function.
0 0
- sklearn中的svm参数介绍
- sklearn中的svm.SVC
- sklearn.svm.SVC 参数说明
- sklearn.svm.SVC 参数说明
- sklearn.svm.SVC 参数说明
- sklearn.svm.SVC 参数说明
- 如何使用sklearn中的SVM
- 关于sklearn.svm.SVC与.NuSVC的区别以及参数介绍
- python 利用库sklearn 中的 grid_search对svm 参数寻优(借鉴)
- SVM基本概要与sklearn.svm.svc 参数说明
- 【sklearn】svm
- sklearn:SVM
- SVM介绍与参数
- SVM参数介绍
- opencv中的SVM参数
- sklearn中 svm.SVC 函数使用方法和参数说明
- sklearn 线性回归LinearRegression()参数介绍
- 如何使用sklearn中的SVM(SVC;SVR)
- Android MVP模式 简单易懂的介绍方式
- Glass Carving-(set)
- 逻辑卷管理器LVM建立
- Java静态与非静态代码块
- 机器学习:Softmax回归
- sklearn中的svm参数介绍
- Struts2的工作原理详解
- SQLite--Vacuum命令(释放空间)
- Labview 串口通信
- 类与对象试验1
- 浅谈Runnable与Callable的区别
- descendantFocusability 的用法和理解+fitSystemWindow的使用
- webStrom中的批量替换
- 浏览器缓存机制