Sklearn RANSAC without intercept

Viewed 642

I am trying to fit a linear model without intercept (forcing the intercept to 0) using sklearn's RANSAC: RANdom SAmple Consensus algorithm. In LinearRegression one can easily set fit_intercept=False. However, this option does not seem to exist in RANSAC's list of possible parameters. Is this functionality not implemented? How should one do it? What are alternatives to sklearn's RANSAC to objectively select inliers and outliers, that allow setting the intercept to 0?

The implementation should look like this, but it raises an error:

from sklearn.linear_model import RANSACRegressor

ransac_regressor = RANSACRegressor(fit_intercept=False)
1 Answers

RANSAC is a wrapper around other linear regressors to implement them using random sampling consesus, thus you can simply set the base_estimator to fit_intercept=False:

from sklearn.linear_model import RANSACRegressor, LinearRegression

ransac_lm = RANSACRegressor(base_estimator=LinearRegression(fit_intercept=False))
Related