Scale Then Vote
Each row of X is a person: age in years and income in dollars, with a label in y (0 or 1). Nearest neighbors compares distances, and raw dollars would drown out the years. Build a pipeline that standardizes the columns and then classifies by the 3 nearest neighbors, fit it, and return its predictions for X_new.
Example 1
X [[20,50000],[22,90000],[25,20000],[30,70000],[50,30000],[55,80000],[60,40000],[65,95000]]
y [0,0,0,0,1,1,1,1]
X_new [[24,85000],[58,25000]]
returns [0,1]
The label follows age here. Once both columns are on the same scale, the 24 year old lands among the young and the 58 year old among the old, whatever they earn.
Constraints
8 <= len(X) <= 501 <= len(X_new) <= 8
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More scikit-learn problems
- Shrunken SlopesMedium
- Two Main DirectionsMedium
- Words to CountsMedium
- How Many GroupsHard
- Keep the Useful ColumnsHard
- Leak-Free ScoreHard
- Mixed ColumnsHard
- Pick the PenaltyHard