Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 进行对数线性回归后计算相关系数_Python_Scikit Learn_Scipy_Correlation - Fatal编程技术网

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

Python 进行对数线性回归后计算相关系数,python,scikit-learn,scipy,correlation,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.42

我正在进行对数线性回归,然后使用两种不同的方法计算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]

打印结果具有明显的指数单元依赖关系:

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

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

这将返回
R\u值**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值不匹配吗? 我的“背向变换”做错了吗

非常感谢您的帮助

干杯