DistrictDataLabs / yellowbrick

Visual analysis and diagnostic tools to facilitate machine learning model selection.
http://www.scikit-yb.org/
Apache License 2.0
4.3k stars 559 forks source link

Can I produce KElbowVisualizer for several (or all) metrics at the same time? #1199

Closed michael135 closed 3 years ago

michael135 commented 3 years ago

Can I produce KElbowVisualizer for several (or all) metrics at the same time?

Something like this:

model = KMeans()
visualizer = KElbowVisualizer(
                                  model, k=(4,12), 
                                  metric=['calinski_harabasz', 'silhouette', 'distortion'] )

Or the only way is just:

model = KMeans()

for metric in ['calinski_harabasz', 'silhouette', 'distortion'] :

     visualizer = KElbowVisualizer(
                                  model, k=(4,12), 
                                  metric=metric)
bbengfort commented 3 years ago

Hello @michael135 thank you for your interest in Yellowbrick! Sorry for the delay in getting back to you, your note got buried in our email. The metric in the KElbowVisualizer is used to detect the inflection point, so unfortunately no, you can't use them all at the same time. If you think that would be an interesting feature, we'd be happy to review a prototype modification.

However, your suggestion for creating three different plots makes a lot of sense to me. If you wanted them in the same figure you could put them all on different subplots, e.g.

import matplotlib.pyplot as plt 

_, axes = plt.subplots(nrows=3)
metrics = ['calinski_harabasz', 'silhouette', 'distortion']

for ax, metric in zip(axes, metrics):
    oz = KElbowVisualizer(model, ax=ax, k=(4,12), metric=metric).fixt(X, y)
    oz.finalize()

plt.show()