Skip to content

Instantly share code, notes, and snippets.

@haridutt12
Created May 30, 2020 17:10
Show Gist options
  • Save haridutt12/2857e7ab9fd088c4c6a904dd1a0fa733 to your computer and use it in GitHub Desktop.
Save haridutt12/2857e7ab9fd088c4c6a904dd1a0fa733 to your computer and use it in GitHub Desktop.
In [99]: import pandas as pd
In [100]: data = pd.read_csv('/home/haridutt/Downloads/automobile.csv')
In [101]: X = data.loc[:, ['type', 'engine_s', 'horsepow', 'mpg']]
In [102]: y = data.iloc[:, 1 ]
In [103]: X_opt = X
In [104]: regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit()
In [105]: regressor_OLS.summary()
Out[105]:
<class 'statsmodels.iolib.summary.Summary'>
"""
OLS Regression Results
=======================================================================================
Dep. Variable: price R-squared (uncentered): 0.943
Model: OLS Adj. R-squared (uncentered): 0.941
Method: Least Squares F-statistic: 623.1
Date: Sat, 30 May 2020 Prob (F-statistic): 3.83e-93
Time: 22:37:31 Log-Likelihood: -533.55
No. Observations: 156 AIC: 1075.
Df Residuals: 152 BIC: 1087.
Df Model: 4
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
type -2.1457 1.443 -1.487 0.139 -4.996 0.705
engine_s -3.6465 1.076 -3.389 0.001 -5.772 -1.521
horsepow 0.2535 0.019 13.571 0.000 0.217 0.290
mpg -0.3319 0.060 -5.506 0.000 -0.451 -0.213
==============================================================================
Omnibus: 63.094 Durbin-Watson: 1.309
Prob(Omnibus): 0.000 Jarque-Bera (JB): 214.094
Skew: 1.554 Prob(JB): 3.24e-47
Kurtosis: 7.825 Cond. No. 500.
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
"""
In [106]: X_opt = X.iloc[:, 1:4]
In [107]: X_opt
Out[107]:
engine_s horsepow mpg
0 1.8 140 25
1 3.2 225 25
2 3.2 225 22
3 3.5 210 22
4 1.8 150 24
.. ... ... ...
151 1.9 160 25
152 2.4 168 25
153 2.4 168 25
154 2.3 236 23
155 2.9 201 24
[156 rows x 3 columns]
In [108]: regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit()
In [109]: regressor_OLS.summary()
Out[109]:
<class 'statsmodels.iolib.summary.Summary'>
"""
OLS Regression Results
=======================================================================================
Dep. Variable: price R-squared (uncentered): 0.942
Model: OLS Adj. R-squared (uncentered): 0.941
Method: Least Squares F-statistic: 823.6
Date: Sat, 30 May 2020 Prob (F-statistic): 3.67e-94
Time: 22:39:33 Log-Likelihood: -534.68
No. Observations: 156 AIC: 1075.
Df Residuals: 153 BIC: 1085.
Df Model: 3
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
engine_s -4.2411 1.003 -4.229 0.000 -6.222 -2.260
horsepow 0.2597 0.018 14.200 0.000 0.224 0.296
mpg -0.3254 0.060 -5.390 0.000 -0.445 -0.206
==============================================================================
Omnibus: 67.561 Durbin-Watson: 1.326
Prob(Omnibus): 0.000 Jarque-Bera (JB): 242.693
Skew: 1.655 Prob(JB): 1.99e-53
Kurtosis: 8.137 Cond. No. 325.
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment