Skip to content

Instantly share code, notes, and snippets.

@orhermansaffar
Created June 27, 2021 14:27
Show Gist options
  • Save orhermansaffar/518ae0a7dcab2d02579dc41e79ae2b41 to your computer and use it in GitHub Desktop.
Save orhermansaffar/518ae0a7dcab2d02579dc41e79ae2b41 to your computer and use it in GitHub Desktop.
def chooseBestKforKMeans(scaled_data, k_range):
ans = []
for k in k_range:
scaled_inertia = kMeansRes(scaled_data, k)
ans.append((k, scaled_inertia))
results = pd.DataFrame(ans, columns = ['k','Scaled Inertia']).set_index('k')
best_k = results.idxmin()[0]
return best_k, results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment