本文介绍了什么时候应该使用LinearSVC或SVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的研究中,我发现了三个相互矛盾的结果:

From my research, I found three conflicting results:

  1. SVC(kernel="linear")更好
  2. LinearSVC更好
  3. 没关系
  1. SVC(kernel="linear") is better
  2. LinearSVC is better
  3. Doesn't matter

有人可以解释何时使用LinearSVCSVC(kernel="linear")吗?

Can someone explain when to use LinearSVC vs. SVC(kernel="linear")?

似乎LinearSVC比SVC稍好,而且通常更挑剔.但是,如果scikit决定花时间在实现线性分类的特定情况下,为什么LinearSVC不会胜过SVC?

It seems like LinearSVC is marginally better than SVC and is usually more finicky. But if scikit decided to spend time on implementing a specific case for linear classification, why wouldn't LinearSVC outperform SVC?

推荐答案

从数学上讲,优化SVM是一个凸优化问题,通常使用唯一的最小化器.这意味着该数学优化问题只有一种解决方案.

Mathematically, optimizing an SVM is a convex optimization problem, usually with a unique minimizer. This means that there is only one solution to this mathematical optimization problem.

结果的差异来自几个方面:SVCLinearSVC应该可以优化同一问题,但是实际上所有liblinear估计量都会对截距进行惩罚,而libsvm估计量则不会(IIRC) .这导致了不同的数学优化问题,并因此产生了不同的结果.可能还存在其他细微的差异,例如缩放比例和默认损失功能(确保在LinearSVC中设置了loss='hinge').接下来,在多类分类中,默认情况下liblinear做一个一对多,而libsvm做一个一对一.

The differences in results come from several aspects: SVC and LinearSVC are supposed to optimize the same problem, but in fact all liblinear estimators penalize the intercept, whereas libsvm ones don't (IIRC). This leads to a different mathematical optimization problem and thus different results. There may also be other subtle differences such as scaling and default loss function (edit: make sure you set loss='hinge' in LinearSVC). Next, in multiclass classification, liblinear does one-vs-rest by default whereas libsvm does one-vs-one.

SGDClassifier(loss='hinge')在使用随机梯度下降而不是精确梯度下降且可能不会收敛于同一解的意义上与其他两个有所不同.但是,所获得的解决方案可能会更好地推广.

SGDClassifier(loss='hinge') is different from the other two in the sense that it uses stochastic gradient descent and not exact gradient descent and may not converge to the same solution. However the obtained solution may generalize better.

SVCLinearSVC之间,一个重要的决策标准是LinearSVC趋于更快收敛,并且样本数量越大.这是因为线性核是一个特例,它是在Liblinear中进行了优化的,但在Libsvm中没有进行优化.

Between SVC and LinearSVC, one important decision criterion is that LinearSVC tends to be faster to converge the larger the number of samples is. This is due to the fact that the linear kernel is a special case, which is optimized for in Liblinear, but not in Libsvm.

这篇关于什么时候应该使用LinearSVC或SVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 07:06