All problems
RANSAC Line Inliers
Problem
Run RANSAC iterations to fit a line. Each iteration picks two distinct points with random.seed(seed), counts points whose perpendicular distance to the line is within threshold, and keeps the model with the most inliers (ties keep the earliest).
Return the sorted inlier indices of the best model. Fewer than two points or iterations <= 0 returns [].
Hint
Sample minimal subsets, count consensus, and keep the largest inlier set.
Test cases
case 1
in: [[0,1,2,3,10],[0,2,4,6,5],42,0.5,10]
expected: [0,1,2,3]
case 2
in: [[0,1,2,3,10],[0,2,4,6,5],7,0.5,5]
expected: [0,1,2,3]
case 3
in: [[1,2],[1,2],0,1,3]
expected: [0,1]
case 4
in: [[1],[1],0,0.5,5]
expected: []
Starter codePython
import math
import random
def ransac_line_inliers(X, y, seed, threshold, iterations):
# Your code here
pass4 test cases · run your code against them in the editor