statsmodels 的 OLS 不适用于成反比的数据?
本文介绍了statsmodels 的 OLS 不适用于成反比的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用一些成反比的数据执行普通最小二乘回归,但似乎拟合结果是错误的?
I'm trying to perform a Ordinary Least Squares Regression with some inversely proportional data, but seems like the fitting result is wrong?
推荐答案
您没有添加常量作为 文档建议,因此它试图将整个内容设为 y = mx
.您最终会得到一个 m
大约为 0.5,因为它正在尽其所能,因为您必须在 0 处为 0,等等.
You're not adding a constant as the documentation suggests, so it's trying to fit the whole thing as y = m x
. You wind up with an m
which is roughly 0.5 because it's doing the best it can, given that you have to be 0 at 0, etc.
以下代码(注意导入的变化)
The following code (note the change in import as well)
生产
系数为 [ 100. -1.]
.
这篇关于statsmodels 的 OLS 不适用于成反比的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!