Please explain or generalize this concept sm.add_constants()?(Method in Statsmodel)
Thanks in advance 🙂
Thanks for reaching out.
OLS requires the input to have a column of ones. We need to add this column manually.
x = sm.add_constant(x1)
adds a column of ones to the
x1 array (
data['SAT']). Here is the head of
As you can see, a column of ones is added to
SAT. This column of ones corresponds to x_0 in the simple linear regression equation: y_hat = b_0 * x_0 + b_1 * x_1. As explained in the lecture video, x_0 is always one and thus the regression equation becomes: y_hat = b_0 * 1 + b_1 * x_1. The
x array holds
The 365 Team