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.
  • $\begingroup$ 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? $\endgroup$ – Manav Kataria Jan 13 '15 at 23:57
  • $\begingroup$ 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. $\endgroup$ – Andy Jones Jan 14 '15 at 0:14
  • $\begingroup$ 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? $\endgroup$ – Andy Jones Jan 14 '15 at 0:20
  • $\begingroup$ Andy, your answers and comments have definitely pointed me in the right direction! Unfortunately, I didn't understand well in advance that the bounty would be lost and not auto-assigned even if you were the only one who had provided an answer, my bad. I will provide you with another bounty for your timely help. To answer your comment above - I am not yet sure what model would suit me best RANSAC, Simulated Annealing or Online Linear Regression. It might be a combination. I am working to figure it out. I've added context. $\endgroup$ – Manav Kataria Jan 16 '15 at 0:53
  • $\begingroup$ StackOverflow isn't letting me add another bounty to this question to reward you back unfortunately. My apologies for not being decisive enough! $\endgroup$ – Manav Kataria Jan 16 '15 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.