Question on simple linear regression example.
In the lecture example, it mentioned the following code:
# Add a constant. Essentially, we are adding a new column (equal in length to x), which consists only of 1s
x = sm.add_constant(x1)
# Fit the model, according to the OLS (ordinary least squares) method with a dependent variable y and an independent x
results = sm.OLS(y,x).fit()
# Print a nice summary of the regression. That's one of the strong points of statsmodels -> the summaries
results.summary() I don't understand what the sm.add_constant do, and why are we fitting x instead of x1 to the statsmodels?
x = sm.add_constant(x1)
# Fit the model, according to the OLS (ordinary least squares) method with a dependent variable y and an independent x
results = sm.OLS(y,x).fit()
# Print a nice summary of the regression. That's one of the strong points of statsmodels -> the summaries
results.summary() I don't understand what the sm.add_constant do, and why are we fitting x instead of x1 to the statsmodels?
1 answers ( 0 marked as helpful)
Hi Kam,
Good question! It is explained in the subsequent lectures!
If after watching them until the end of the section you are still having this question, please come back here and we will dive deeper into it :)
Best,
The 365 Team
The 365 Team