【发布时间】:2019-10-20 07:58:42
【问题描述】:
我正在尝试使用普通最小二乘法进行多变量回归。但它说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(
错误如下:
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的版本,是不是>= 0.5.0?类似print (statsmodels.__version__) -
使用
import statsmodels.api as sm。formula.api现在只有小写模型的公式接口,例如ols
标签: python machine-learning linear-regression statsmodels