本文介绍了AttributeError:模块"statsmodels.formula.api"没有属性"OLS"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用普通最小二乘进行多元回归.但是它说statsmodels没有属性'OLS'.公式. api库.我正在遵循有关Udemy的演讲中的代码代码如下:

I am trying to use Ordinary Least Squares for multivariable regression. But it says that there is no attribute 'OLS' from statsmodels. formula. api library.I am following the code from a lecture on UdemyThe code is as follows:

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.10.0:

Just for completeness, the code should look like this if statsmodels.version is 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()

这篇关于AttributeError:模块"statsmodels.formula.api"没有属性"OLS"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 08:15