sm.add_constants()
Hi All,
Please explain or generalize this concept sm.add_constants()?(Method in Statsmodel)
Thanks in advance :)
2 answers ( 0 marked as helpful)
Hi Anuridh,
Thanks for reaching out.
OLS requires the input to have a column of ones. We need to add this column manually.
The 365 Team
x = sm.add_constant(x1)
adds a column of ones to the x1
array (data['SAT']
). Here is the head of x
:
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 1
and x_1
.
Best,The 365 Team
thanks for the answer data365 team, currently learn your course on udemy. and im dying to know what is add_contsant do lol