FunctionRacerProblemsRace

How Many Groups

Hardscikit-learnPython

The rows of X are points in some number of groups, and nobody says how many. For each k from 2 to 6, cluster them with k-means (n_init=3, random_state=0) and compute the silhouette score of the labels it assigns, which is high when points sit close to their own group and far from the others. Return the k with the highest score.

Example 1

X [[0,0],[0,1],[1,0],[1,1],[0.5,0.5],[10,10],[10,11],[11,10],[11,11],[10.5,10.5],[0,10],[0,11],[1,10],[1,11],[0.5,10.5],[10,0],[10,1],[11,0],[11,1],[10.5,0.5]]
returns 4

Four tight clumps at the corners of a square.

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