The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

sm.add_constants()

sm.add_constants()

0
Votes
1
Answer

Hi All,
 
Please explain or generalize this concept sm.add_constants()?(Method in Statsmodel)
 
 
Thanks in advance 🙂
 

1 Answer

365 Team
0
Votes

Hi Anuridh,
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 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