FunctionRacerProblemsRace

Vote of the Neighbors

Easyscikit-learnPython

Each row of X is a point with a label in y (0 or 1). Classify each row of X_new by the majority label of its k nearest points in X, where k is odd.

Example 1

X [[0,0],[1,0],[0,1],[9,9],[8,9]]
y [0,0,0,1,1]
X_new [[1,1],[9,8]]
k 3
returns [0,1]

The three points nearest (1, 1) all have label 0. Nearest (9, 8) are the two points with label 1 and one far away with label 0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More scikit-learn problems