python - 属性错误 : module 'statsmodels.formula.api' has no attribute 'OLS'

标签 python machine-learning linear-regression statsmodels

我正在尝试使用普通最小二乘法进行多元回归。但它说 statsmodels 没有属性“OLS”。公式。接口(interface)库。 我正在遵循 Udemy 讲座中的代码 代码如下:

import statsmodels.formula.api as sm
X_opt = X[:,[0,1,2,3,4,5]]
#OrdinaryLeastSquares
regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit(

错误如下:

AttributeError                            Traceback (most recent call last)
<ipython-input-19-3bdb0bc861c6> in <module>()
      2 X_opt = X[:,[0,1,2,3,4,5]]
      3 #OrdinaryLeatSquares
----> 4 regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit()

AttributeError: module 'statsmodels.formula.api' has no attribute 'OLS'

最佳答案

为了完整起见,如果 statsmodels.version 为 0.10.0,代码应该如下所示:

import statsmodels.api as sm
X_opt = X[:,[0,1,2,3,4,5]]
#OrdinaryLeastSquares
regressor_OLS = sm.OLS(endog=y, exog=X_opt).fit()

关于python - 属性错误 : module 'statsmodels.formula.api' has no attribute 'OLS' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56449787/

相关文章:

python - 如何使用 Tensorflow LSTM 获得预测的 future 跟随值?

machine-learning - 为什么向线性回归添加特征会降低准确性?

r - 识别数据中的几个精确线性关系

python - pandas 的变换不起作用对 groupby 输出进行排序

python - Cloning Conda root环境不会克隆conda和condo-build

tensorflow - 为什么 Conv2D 每层有不同数量的滤波器

python-3.x - 如何找到回归线与 OY 轴相交的点?

python - 弹性 beantalk 上的 psycopg2 - 无法部署应用程序

python - 使用提供给构造函数的数据列表在数据帧构造函数中设置多索引

language-agnostic - 自动同义词检测方法