【问题标题】:Slope from linear regression线性回归的斜率
【发布时间】:2019-07-13 07:07:40
【问题描述】:

我有一个阴谋-

当我尝试对其进行线性回归时-

df=pd.read_csv('tau.csv')


xx= df['xx'].tolist()
yy=df['yy'].tolist()
from scipy.stats import linregress
#print(linregress(xx,yy))

slope, intercept, r_value, p_value, std_err=linregress(xx,yy)
print(slope)

plt.plot(xx,yy,'ro')
plt.xlabel('log(l)')
plt.ylabel('log(Rl)')
plt.title('Fractal dimension with '+str(slope))
plt.show()

我得到的斜率是 nan。

我的数据-

【问题讨论】:

标签: python pandas numpy scipy


【解决方案1】:

您的数据中似乎有 nan

x = [1,2, np.nan]
y = [2,4,6]

linregress(x,y)

>>> LinregressResult(slope=nan, intercept=nan, rvalue=nan, pvalue=nan, stderr=nan)

另外,您不需要将系列转换为列表,您当然可以这样做:

lingress(df['xx'], df['yy'])

【讨论】:

  • 这看起来是正确的解释,尽管 scipy 1.3 linregress 的文档似乎声称丢失的数据是“成对”处理的。查看“linregress”的来源,我认为不是这样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-05
  • 2021-02-25
  • 2016-01-22
  • 1970-01-01
  • 1970-01-01
  • 2016-06-07
  • 2021-06-22
相关资源
最近更新 更多