Logistic回归中正则化强度的倒数是什么?它应如何影响我的代码? [英] What is the inverse of regularization strength in Logistic Regression? How should it affect my code?

查看:464
本文介绍了Logistic回归中正则化强度的倒数是什么?它应如何影响我的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在scikit learn进行Logistic回归.

I am using sklearn.linear_model.LogisticRegression in scikit learn to run a Logistic Regression.

C : float, optional (default=1.0) Inverse of regularization strength;
    must be a positive float. Like in support vector machines, smaller
    values specify stronger regularization.

C此处的简单含义是什么?什么是正则化强度?

What does C mean here in simple terms please? What is regularization strength?

推荐答案

正则化采取措施增加参数值的大小,以减少过度拟合.当训练诸如逻辑回归模型之类的模型时,您正在选择最适合数据的参数.这意味着将模型在给定数据的情况下对因变量的预测与实际因变量之间的误差最小化.

Regularization is applying a penalty to increasing the magnitude of parameter values in order to reduce overfitting. When you train a model such as a logistic regression model, you are choosing parameters that give you the best fit to the data. This means minimizing the error between what the model predicts for your dependent variable given your data compared to what your dependent variable actually is.

当您有很多参数(很多自变量)但没有太多数据时,就会出现问题.在这种情况下,模型通常会根据您数据中的特质来调整参数值-这意味着它几乎可以完美地适合您的数据.但是,由于这些特质不会出现在您看到的未来数据中,因此您的模型预测效果不佳.

The problem comes when you have a lot of parameters (a lot of independent variables) but not too much data. In this case, the model will often tailor the parameter values to idiosyncrasies in your data -- which means it fits your data almost perfectly. However because those idiosyncrasies don't appear in future data you see, your model predicts poorly.

要解决此问题,并尽可能减少已讨论的错误,您可以添加到最小化的内容中,还可以最小化惩罚较大参数值的函数.最常见的函数是λΣθ j 2 ,它是常数λ乘以平方参数值θ j 2 . λ越大,仅为了适应数据中的小扰动而调整参数的幅度的可能性就越小.但是,根据您的情况,而不是指定λ,而是指定C = 1/λ.

To solve this, as well as minimizing the error as already discussed, you add to what is minimized and also minimize a function that penalizes large values of the parameters. Most often the function is λΣθj2, which is some constant λ times the sum of the squared parameter values θj2. The larger λ is the less likely it is that the parameters will be increased in magnitude simply to adjust for small perturbations in the data. In your case however, rather than specifying λ, you specify C=1/λ.

这篇关于Logistic回归中正则化强度的倒数是什么?它应如何影响我的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆