Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 Udemy The 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(

The error is as follows:

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'
like image 217
Shubham Trehan Avatar asked Jun 04 '19 18:06

Shubham Trehan


2 Answers

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()
like image 177
chefer Avatar answered Sep 21 '22 12:09

chefer


Use this import.

import statsmodels.api as sm
like image 25
Ankit Pal Avatar answered Sep 20 '22 12:09

Ankit Pal