对数线性回归后计算相关系数

时间:2020-10-30 15:34:12

标签: python scikit-learn scipy correlation

我正在执行对数线性回归,然后我使用两种不同的方法来计算R ^ 2值。问题在于方法为R ^ 2返回不同的值。 我的数据看起来像这样:

x = [0.03553744809541667, 0.07393361944488888, 0.11713398354352941, 0.1574279442442857, 0.20574484316400002, 0.24638269718399997, 0.28022173237600007, 0.33088392763600005, 0.37608523866, 0.4235348808, 0.4698941935266667, 0.5049780023645001, 0.53193232248, 0.59661874698, 0.64686695376, 0.6765964062965002, 0.7195010072795001, 0.7624056082625001, 0.8053102092455002, 0.8696671107200001]

y = [1.0, 0.9180040755624065, 0.7580780029008654, 0.662359339541471, 0.556415757973503, 0.4575163368602455, 0.3982995279500034, 0.3309496816813175, 0.25142343840921577, 0.21526738042912116, 0.19490849614884595, 0.12714651046365663, 0.12714651046365663, 0.1015770731180174, 0.0728982261567812, 0.04180399979351543, 0.04180399979351543, 0.04180399979351543, 0.04180399979351543, 0.04180399979351543]

绘图会导致明显的指数依赖性: enter image description here

我正在尝试使用以下方法拟合线性模型:

slope, intercept, r_value, _, _ = linregress(x, np.log(y))

这将返回r_value**2 = 0.978的R ^ 2值

但是,当我尝试使用sklearns函数计算R ^ 2值时,R ^ 2值是不同的:

y_pred = [math.exp(slope*i+intercept) for i in x]
r2 = r2_score(y,y_pred)

这将返回0.9906作为R ^ 2。

有人可以告诉我为什么R ^ 2值不匹配吗? 我在做“反向转换”错误吗?

非常感谢您的帮助!

干杯!

0 个答案:

没有答案