In some version of
'statsmodels' OLS is directly available in
statsmodels.api. So we don't have to use
'statsmodels.formula.api', instead of it, we can use
'statsmodels.api'. So final syntax would be like-
Code:-
import statsmodels.formula.api as sm
model_ols = sm.OLS(endog=y, exog=X).fit()
Output:-
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-39f3885d5ce0> in <module>
----> 1 model_ols = sm.OLS(endog=y, exog=X).fit()
AttributeError: module 'statsmodels.formula.api' has no attribute 'OLS'
How we can fix:-
import statsmodels.api as sm
model_ols = sm.OLS(endog=y, exog=X).fit()
model_ols.summary()
Output:-
OLS Regression Results
Dep. Variable: | Profit | R-squared (uncentered): | 0.988 |
Model: | OLS | Adj. R-squared (uncentered): | 0.986 |
Method: | Least Squares | F-statistic: | 727.1 |
Date: | Fri, 17 Apr 2020 | Prob (F-statistic): | 7.87e-42 |
Time: | 15:19:25 | Log-Likelihood: | -545.15 |
No. Observations: | 50 | AIC: | 1100. |
Df Residuals: | 45 | BIC: | 1110. |
Df Model: | 5 | | |
Covariance Type: | nonrobust | | |
| coef | std err | t | P>|t| | [0.025 | 0.975] |
R&D Spend | 0.7182 | 0.066 | 10.916 | 0.000 | 0.586 | 0.851 |
Administration | 0.3113 | 0.035 | 8.885 | 0.000 | 0.241 | 0.382 |
Marketing Spend | 0.0786 | 0.023 | 3.429 | 0.001 | 0.032 | 0.125 |
State_Florida | 3464.4536 | 4905.406 | 0.706 | 0.484 | -6415.541 | 1.33e+04 |
State_New York | 5067.8937 | 4668.238 | 1.086 | 0.283 | -4334.419 | 1.45e+04 |
Omnibus: | 1.355 | Durbin-Watson: | 1.288 |
Prob(Omnibus): | 0.508 | Jarque-Bera (JB): | 1.241 |
Skew: | -0.237 | Prob(JB): | 0.538 |
Kurtosis: | 2.391 | Cond. No. | 8.28e+05 |
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 8.28e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
Comments
Post a Comment
Please share your experience.....