Skip to content
Advertisement

In the LinearRegression method in sklearn, what exactly is the fit_intercept parameter doing? [closed]

In the sklearn.linear_model.LinearRegression method, there is a parameter that is fit_intercept = TRUE or fit_intercept = FALSE. I am wondering if we set it to TRUE, does it add an additional intercept column of all 1’s to your dataset? If I already have a dataset with a column of 1’s, does fit_intercept = FALSE account for that or does it force it to fit a zero intercept model?

Update: It seems people do not get my question. The question is, what IF I had already a column of 1’s in my dataset of predictors (the 1’s are for the intercept). THEN,

  1. if I use fit_intercept = FALSE, will it remove the column of 1’s?

  2. if I use fit_intercept = TRUE, will it add an EXTRA column of 1’s?

Advertisement

Answer

fit_intercept=False sets the y-intercept to 0. If fit_intercept=True, the y-intercept will be determined by the line of best fit.

JavaScript

This example prints:

JavaScript

Visually it becomes clear what fit_intercept does. When fit_intercept=True, the line of best fit is allowed to “fit” the y-axis (close to 100 in this example). When fit_intercept=False, the intercept is forced to the origin (0, 0).

fit_intercept in sklearn


What happens if I include a column of ones or zeros and set fit_intercept to True or False?

Below shows an example of how to inspect this.

JavaScript

Take-away:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement