python - Scipy 线性回归不包括`intercept_stderr` 属性
问题描述
我正在尝试使用 scipy 对一组二维点执行线性回归。如文档here所述,适当的调用是
regression_results = scipy.stats.linregress(x_values, y_values)
文档指出该regression_results
对象包含以下值:slope, intercept, rvalue, pvalue, stderr, intercept_stderr
. 除了最后一个,所有这些都存在。
这些值都存在于字典中,但intercept_stderr
根本不是。我终其一生都无法理解为什么。这是我尝试运行的简单代码:
from scipy import stats
# given two lists nmeq_x and nmeq_y...
result = stats.linregress(nmeq_x, nmeq_y)
print(result.intercept, result.intercept_stderr)
我得到错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-18-7df9d260a3bb> in <module>
1 result = stats.linregress(nmeq_x, nmeq_y)
----> 2 print(result.intercept, result.intercept_stderr)
AttributeError: 'LinregressResult' object has no attribute 'intercept_stderr'
解决方案
这是关于你的 scipy 版本;此功能是在 2020-12-31 发布的 1.6 中添加的。
请注意,文档是这样说的:
为了与旧版本的 SciPy 兼容,返回值的作用类似于长度为 5 的命名元组,包含字段 slope、intercept、rvalue、pvalue 和 stderr
那么,您必须拥有这些旧版本之一。该intercept_stderr
字段是最近添加的。将您的 scipy 更新到 1.6。
推荐阅读
- java - 在 Eclipse 中使用 Java 多线程不再终止 Java 主类线程
- angular - 如何在 Angular 中编写自定义的特殊属性绑定?
- label - AmCharts 将背景颜色添加到 valueAxes 指南标签
- python - 用户警告:布尔系列键将被重新索引以匹配 DataFrame 索引
- javascript - 背景图像 url 中的属性
- java - 无法部署到 TomEE 的 ActiveWeb 战争
- javascript - 通过 props 用 React.js 交换 HTML 元素
- android - RxJava:在 Kotlin 中使用 combineLatest 和 3 个不同的流
- amazon-web-services - 使用 cloudformation 在 Elastic Beanstalk 上启动 docker 多容器
- powershell - 如何使用 PowerShell 动态调用 Commandlet?