【问题标题】:SVC vs LinearSVC in scikit learn: difference of loss functionscikit learn中的SVC vs LinearSVC:损失函数的区别
【发布时间】:2021-01-23 05:26:15
【问题描述】:

根据this post,scikit learn中的SVC和LinearSVC有很大的不同。但是看official scikit learn documentation的时候,就不是那么清楚了。

特别是对于损失函数,似乎有一个等价性:

this post 说 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】:

    SVCLIBSVM 库的包装器,而LinearSVCLIBLINEAR 的包装器

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

    引用LIBLINEARFAQ

    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.
    

    【讨论】:

    • 不同之处不仅在于速度,还在于它们的不同。我做了一个简单的例子here。你也可以阅读this
    • 我的问题是关于两个分类器的损失函数。谢谢
    • 更多实现细节可以在原文LIBLINEARpaper的附录中找到
    • post中的答案是正确的。 LIBLINEAR 确实包含优化中的偏差项,而 LIBSVM 没有。
    • SVC 默认为 L1 损失和 L2 惩罚。这就是为什么您可以在两者的结果几乎相等时创建条件,如果您为LinearSVMloss="hinge"intercept_scaling 设置足够大。偏置项包含在LIBLINEAR 中,因为权重向量隐式扩展为w=[w;b]。如果在优化之前将数据居中,它应该有效地将偏差设置为零。
    猜你喜欢
    • 2016-02-23
    • 2015-03-10
    • 2016-02-23
    • 2019-06-13
    • 2014-09-22
    • 2020-09-25
    • 2018-01-05
    • 2019-06-13
    • 2023-04-07
    相关资源
    最近更新 更多