gpt4 book ai didi

data-science - 如何获得线性回归的调整 R 方

转载 作者:行者123 更新时间:2023-12-04 02:59:01 33 4
gpt4 key购买 nike

使用 sklearn.metrics 我可以计算 R 方。如何使用线性回归模型计算 Adjusted Adjusted R 方?

最佳答案

Scikit-Learn 的线性回归不会返回调整后的 R 平方。但是,根据 R 平方,您可以通过以下公式计算调整后的 R 平方:

enter image description here

其中 p 是预测变量(也称为特征或解释变量)的数量,n 是数据点的数量。因此,如果您的数据位于名为 train 的数据框中,并且您有 r 平方 r2,则公式为:

adj_r2 = (1 - (1 - r2) * ((train.shape[0] - 1) / 
(train.shape[0] - train.shape[1] - 1)))

train.shape[0] 是观测数,train.shape[1] 是特征数。

StatsModels库有一个线性回归方法,它确实返回调整后的 R 平方(以及许多其他指标)。 Here is the documentation.

以上公式来自this Stack Exchange Answer这表示这被称为 Wherry Formula - 1。有许多不同的公式可用于计算调整后的 R 平方,但这是 R 中使用的方法。有关调整后的 R 平方方法之间差异的更多信息,请参阅链接的答案或论文 Estimating R^2 Shrinkage in Regression

关于data-science - 如何获得线性回归的调整 R 方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51023806/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com