

.. _example_linear_model_plot_robust_fit.py:


Robust linear estimator fitting
===============================

Here a sine function is fit with a polynomial of order 3, for values
close to zero.

Robust fitting is demoed in different situations:

- No measurement errors, only modelling errors (fitting a sine with a
  polynomial)

- Measurement errors in X

- Measurement errors in y

The median absolute deviation to non corrupt new data is used to judge
the quality of the prediction.

What we can see that:

- RANSAC is good for strong outliers in the y direction

- TheilSen is good for small outliers, both in direction X and y, but has
  a break point above which it performs worst than OLS.



**Python source code:** :download:`plot_robust_fit.py <plot_robust_fit.py>`

.. literalinclude:: plot_robust_fit.py
    :lines: 28-
    