# Is it possible to seed RANSAC with a given line?

I am analyzing a stream of data and I want to seed every new instance with the best guess output (line) of the previous, so as to eventually converge.

Given that Scikit Learn - RANSAC is an iterative model is it possible to seed it with a best-guess / prior linear model to aid outlier detection and model-fitting?

Update: Context

I am working on a lane detection system using a stream of video frames. I use RANSAC for lane detection after passing the image through various filters. Given that lanes do not vary much across adjacent frames I could seed the output of the previous frame to the current (useful when the filters don't yield a good signal/noise ration, for example: bridge shadows / sun glare in frames).

Here's RANSAC in a nutshell:

1. Pick a random subset of samples
2. Fit the model on the subset
3. Add any sample with a small residual to the subset
4. Score the model on the subset, and test if it's the best score so far
5. If it is, store the model
6. Try again

Notice that the only information used from previous iterations is the best-so-far score. So the only way you could "seed" RANSAC is to provide the score of your linear model on the subset closest to the line.

Now SKL doesn't support that functionality out the box, but fortunately Python is an interpreted language, so it's pretty easy to add. All you need to do is take the RANSAC source and

• Change all references of score_best to self.score_best
• Change the initialization score_best = np.inf to if not self.score_best: self.score_best = np.inf
• Then you can seed the model by instantiating a RANSACRegressor object and setting model.score_best.
• Thanks for the answer @andy-jones! I've never messed with SKL source. Your answer is an encouragement to start! I want to seed a line/estimator model for which I am considering using subset_idxs as a seed. Thoughts? Would just seeding score_best yield a worthy estimator? – Manav Kataria Jan 13 '15 at 23:57
• I'm not quite sure what you want: do you want the active set to be carried forward through iterations, with each iteration adding/removing a few indices and refitting the model to see if it's better? If so, that isn't RANSAC. It'd be better suited by simulated annealing. – Andy Jones Jan 14 '15 at 0:14
• I've just reread your post and remembered you're working with data streams. Could this be what you want, an "online" (stream) algorithm for fitting linear regression models? – Andy Jones Jan 14 '15 at 0:20