小编Shu*_*han的帖子

AttributeError:模块“ statsmodels.formula.api”没有属性“ OLS”

我正在尝试使用普通最小二乘进行多元回归。但是它说statsmodels没有属性'OLS'。式。api库。我正在遵循有关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(
Run Code Online (Sandbox Code Playgroud)

错误如下:

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'
Run Code Online (Sandbox Code Playgroud)

python machine-learning linear-regression statsmodels

3
推荐指数
4
解决办法
5494
查看次数