scikit learn 中的 SVC 与 LinearSVC:损失函数的差异

问题描述 投票:0回答:1

根据这篇文章,scikit learn 中的 SVC 和 LinearSVC 有很大不同。但是当阅读官方 scikit learn 文档时,并没有那么清楚。

特别是对于损失函数,似乎存在等价关系:

并且这篇文章说le损失函数是不同的:

  • SVC:
    1/2||w||^2 + C SUM xi_i
  • 线性SVC:
    1/2||[w b]||^2 + C SUM xi_i

看起来在LinearSVC的情况下,截距是正则化的,但官方文档却另有说法。

有人有更多信息吗?

python scikit-learn svm libsvm
1个回答
4
投票

SVC
LIBSVM库的包装,而
LinearSVC
LIBLINEAR

的包装

LinearSVC
通常
SVC
更快,并且可以处理更大的数据集,但它只能使用线性内核,因此得名。所以区别不在于表述,而在于实施方式。

引用

LIBLINEAR
常见问题解答

When to use LIBLINEAR but not LIBSVM

There are some large data for which with/without nonlinear mappings gives similar performances. 
Without using kernels, one can quickly train a much larger set via a linear classifier. 
Document classification is one such application. 
In the following example (20,242 instances and 47,236 features; available on LIBSVM data sets), 
the cross-validation time is significantly reduced by using LIBLINEAR:

% time libsvm-2.85/svm-train -c 4 -t 0 -e 0.1 -m 800 -v 5 rcv1_train.binary
Cross Validation Accuracy = 96.8136%
345.569s

% time liblinear-1.21/train -c 4 -e 0.1 -v 5 rcv1_train.binary
Cross Validation Accuracy = 97.0161%
2.944s

Warning:While LIBLINEAR's default solver is very fast for document classification, it may be slow in other situations. See Appendix C of our SVM guide about using other solvers in LIBLINEAR.
Warning:If you are a beginner and your data sets are not large, you should consider LIBSVM first.
© www.soinside.com 2019 - 2024. All rights reserved.