sklearn Logistic回归中的困惑

2024-05-23 15:54:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在读Logistic回归的documentation,遇到了一个混乱。尤其是,我对fit_intercept和{}的用法感到困惑

fit_intercept : bool, default: True

Specifies if a constant (a.k.a. bias or intercept) should be added to the decision function.

intercept_scaling : float, default 1.

Useful only when the solver liblinear is used and self.fit_intercept is set to True. In this case, x becomes [x, self.intercept_scaling], i.e. a "synthetic" feature with constant value equal to intercept_scaling is appended to the instance vector. The intercept becomes intercept_scaling * synthetic_feature_weight.

Note! the synthetic feature weight is subject to l1/l2 regularization as all other features. To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased.

据我所知,intercept作为数据集的一个虚拟特性,因为每次进行预测时,它都被添加到输出中。在

intercept_scaling下面的一段中,提到了-

a "synthetic" feature with constant value equal to intercept_scaling is appended to the instance vector

但这两个不是一回事吗?这是我的首要问题和困惑。在

最后,文档提到,只有当我使用liblinear作为解算器时,这才有用。如果这两个确实是一样的,并且我将fit_intercept作为{},那么会发生什么呢?在


Tags: andthetotruedefaultisbefeature
1条回答
网友
1楼 · 发布于 2024-05-23 15:54:27

fit_intercept只是一个指令,告诉sklearn向决策函数添加一个截获。然而,由于截距必须被学习,那么synthetic_feature_weight就会起作用,这基本上就是截获。intercept_scaling在正则化中起作用,因为截距也会受到惩罚,所以通过增加intercept_scaling给截距项更多的权重来抵消惩罚。在

我没有找到任何理由来更改intercept_scaling参数,因为毕竟,截距将由算法学习,所以如果你甚至不知道截距是什么,那么为什么要缩放它的效果?在

相关问题 更多 >