In this example we see how to robustly fit a linear model to faulty data using the RANSAC algorithm.
Out: Estimated coefficients (true, normal, RANSAC):
82.1903908408 [ 54.17236387] [ 82.08533159]
import numpy as np
from matplotlib import pyplot as plt
from sklearn import linear_model, datasets
n_samples = 1000
n_outliers = 50
X, y, coef = datasets.make_regression(n_samples=n_samples, n_features=1,
n_informative=1, noise=10,