Python_Codes_Regression - Jupyter Notebook
Python_Codes_Regression - Jupyter Notebook
Simple Regression
In [1]: 1 import pandas as pd
2 import numpy as np
3 import matplotlib.pyplot as plt
4 import warnings
5 warnings.filterwarnings('ignore')
6 import statsmodels.formula.api as smf
7 import statsmodels.api as sm
localhost:8888/notebooks/Python_Codes_Regression.ipynb 1/7
11/24/24, 2:31 PM Python_Codes_Regression - Jupyter Notebook
Intercept 20.157895
RDE 1.973684
dtype: float64
Out[5]: 0 39.894737
dtype: float64
localhost:8888/notebooks/Python_Codes_Regression.ipynb 2/7
11/24/24, 2:31 PM Python_Codes_Regression - Jupyter Notebook
In [6]: 1 df_rd=pd.read_excel("R&D_Profit.xlsx")
2 df_rd
Out[6]:
R&D Expenditure (Millions) Annual Profit (Millions)
0 2 20
1 3 25
2 5 34
3 4 30
4 11 40
5 5 31
localhost:8888/notebooks/Python_Codes_Regression.ipynb 3/7
11/24/24, 2:31 PM Python_Codes_Regression - Jupyter Notebook
Notes:
[1] Standard Errors assume that the covariance matrix of the errors i
s correctly specified.
localhost:8888/notebooks/Python_Codes_Regression.ipynb 4/7
11/24/24, 2:31 PM Python_Codes_Regression - Jupyter Notebook
C:\Users\91941\anaconda3\lib\site-packages\statsmodels\stats\stattool
s.py:74: ValueWarning: omni_normtest is not valid with less than 8 ob
servations; 6 samples were given.
warn("omni_normtest is not valid with less than 8 observations; %i
"
Out[8]:
OLS Regression Results
Df Model: 1
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly
specified.
Out[9]:
Bars Price Promotion
0 4141 59 200
1 3842 59 200
2 3056 59 200
3 3519 59 200
4 4226 59 400
localhost:8888/notebooks/Python_Codes_Regression.ipynb 5/7
11/24/24, 2:31 PM Python_Codes_Regression - Jupyter Notebook
In [10]: 1 data.describe()
Out[10]:
Bars Price Promotion
Intercept 5837.520759
Price -53.217336
Promotion 3.613058
dtype: float64
localhost:8888/notebooks/Python_Codes_Regression.ipynb 6/7
11/24/24, 2:31 PM Python_Codes_Regression - Jupyter Notebook
In [12]: 1 lm.summary()
Out[12]:
OLS Regression Results
Df Model: 2
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly
specified.
[2] The condition number is large, 2.45e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
Out[13]: 0 3078.574405
dtype: float64
In [ ]: 1
localhost:8888/notebooks/Python_Codes_Regression.ipynb 7/7