- Introduced by
- Fischler & Bolles
- Year
- 1981
- Type
- Robust linear regression
What does it do?
RANSAC (Random Sample Consensus) is a general model-fitting paradigm introduced by Fischler and Bolles in 1981 for data containing gross errors.
Applied to linear regression, it repeatedly fits candidate models to small random subsets of points and keeps the model supported by the largest set of points lying within a residual threshold. The final coefficients are estimated from those inliers only, so the outliers are excluded rather than modelled.
The intuition behind the method
Imagine a scatter of points where some are genuine and some are gross errors. Rather than letting the bad points drag the line, RANSAC keeps drawing tiny random samples of points, draws a trial line through each, and counts how many of the remaining points fall close to that line. The line that attracts the biggest crowd of close-by points wins, and the far-away points are simply set aside as outliers.
History
RANSAC was introduced by Fischler and Bolles in 1981 in Communications of the ACM as a paradigm for fitting models to data containing a significant percentage of gross errors. Its motivating applications were image analysis and automated cartography, in particular the Location Determination Problem. Its use for linear regression is an application of the same consensus idea. Torr and Zisserman (2000) later published MLESAC, a related robust estimator developed for estimating image geometry.
When to use it
Choose RANSAC Regression when the relationship is approximately linear, the outcome is continuous, and a meaningful share of observations may be gross errors that should be excluded rather than modelled. The method depends on random subsets finding a consensus, so it needs enough observations for those subsets to represent the main linear pattern; with very small samples, a deterministic estimator such as Theil-Sen is usually the safer choice. It works best when the inliers genuinely follow one linear model. Before applying it, decide on the residual threshold, the subset size and the number of trials, since the trial count needed grows with the outlier share. Do not use it when outliers make up a large share of the data, or when the goal is to model the outlier structure itself rather than to set it aside.
Limitations and considerations
- The number of random trials needed to draw at least one clean subset rises as the outlier share grows, so with many gross errors the search becomes costly and less reliable.
- With few observations, a random subset may not represent the underlying line, so the consensus can be driven by chance configurations of points.
- The inlier set depends on the residual threshold and the number of trials, so different settings can yield different fits.
- Points close to the threshold can switch between inlier and outlier status with small changes in its value, which changes the final fit.
- Standard errors and p-values from the inlier refit ignore the selection of inliers and should not be reported as ordinary inference without validation.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Designed to tolerate a significant percentage of gross errors in the data, as the original formulation describes.
- Excludes gross outliers from the final fit without requiring them to be identified in advance.
- Coefficients are read like ordinary regression coefficients but are estimated from the inlier points only. The consensus step relies on a residual threshold rather than a distributional assumption about the errors. The final refit is ordinary least squares on the inliers, so its usual assumptions apply to that inlier set, although its inferential output does not reflect the data-driven inlier selection.
Applications
- Fitting a linear trend to continuous measurements in which a minority of readings are gross errors, such as those produced by a faulty sensor.
- Estimating a line or plane from feature-based measurements produced by error-prone detectors, the setting the 1981 paper was written for.
- Image-based tasks such as recovering a location from observations of landmarks with known positions, the Location Determination Problem treated in the original paper.
How it works
How it works
The outcome y is modelled as a linear function of the predictors X plus an error term ε, the standard linear regression form. Fischler and Bolles introduced the general consensus paradigm for fitting a model to data containing gross errors; applying it to this linear model is a standard use of that paradigm. What changes relative to ordinary regression is how the coefficients β are chosen so that gross outliers do not distort the fit.
Formula
y = X\beta + \varepsilon
RANSAC repeatedly draws a minimal random subset of points, fits a candidate model to it, and counts how many of the remaining points lie within a residual threshold t of that model; these are the inliers, or the consensus set. After many trials it keeps the model with the largest consensus and refits it on those inliers, so points outside the threshold are excluded from the final fit. Because the inlier set is chosen from the data, standard errors, t-statistics and p-values from an ordinary least squares refit do not account for that selection and are likely to be too optimistic. Treat them as descriptive unless they have been validated, for example by bootstrapping the whole RANSAC procedure.
Formula
\hat{\beta} = \arg\max_{\beta}\; \bigl|\{\, i : |y_i - x_i^{\top}\beta| \le t \,\}\bigr|Common pitfalls
- Running the method on very few observations, where the random subsets may not represent the line and the consensus is unstable.
- Allowing the outlier share to become large, where the number of trials required makes the procedure costly; a deterministic robust method such as least trimmed squares may then be preferable.
- Setting the residual threshold without considering the scale of the residuals, since it directly decides which points count as inliers.
- Reporting one inlier set without checking how the coefficients change with the threshold and the number of trials.
- Reporting the refit's standard errors and p-values as ordinary inference, although they ignore how the inliers were selected.
Frequently asked questions
How is RANSAC different from ordinary least squares?
OLS fits all points at once and is easily pulled off course by outliers, because it minimises the squared error of every point. RANSAC instead fits to a consensus of inlier points and excludes the points outside the threshold, so a handful of gross errors does not distort the line.
How many outliers can RANSAC handle?
It is designed to tolerate a significant share of gross errors, but as that share grows the number of random trials needed to find a clean consensus rises sharply. At high outlier shares a deterministic robust method such as least trimmed squares is usually preferable.
What does the residual threshold do?
The residual threshold defines how close a point must be to a candidate model to count as an inlier. It directly controls which points enter the consensus set, so it should be set with reference to the scale of the residuals and its effect on the result checked.
When should I use Theil-Sen instead?
When the sample is small, random subsets may not represent the underlying line and the consensus becomes unreliable. A deterministic estimator such as Theil-Sen is then a more dependable robust alternative.
Related methods
Sources
Fischler, M. A. & Bolles, R. C. (1981). Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography. Communications of the ACM, 24(6), 381-395.
Open DOI referenceTorr, P. H. S. & Zisserman, A. (2000). MLESAC: A New Robust Estimator with Application to Estimating Image Geometry. Computer Vision and Image Understanding, 78(1), 138-156.
Open DOI reference