WIP: Allows Silhouette Visualizer to accept DensityEstimator #1304
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #1303, which reported that they could not use GMM as a clustering model with Silhouette Visualizer.
They received this traceback:
yellowbrick.exceptions.YellowbrickTypeError: The supplied model is not a clustering estimator; try a classifier or regression score visualizer instead!
Once I resolved the above issue, I encountered another problem with GMM not having a
n_clusters
attribute on the estimator.I have made the following changes:
is_density
function to the utils/types fileis_density
function with the ClusteringScoreVisualizer Class to allow for DensityEstimators to be used by this class3. I fixed the attribute error by using a try/except clause to setself.n_clusters_
equal toself.estimator.n_components
in silhouette.py fileSample Code
from sklearn.mixture import GaussianMixture as GMM
from yellowbrick.cluster import SilhouetteVisualizer
from sklearn.datasets import make_blobs
X, y = make_blobs(
n_samples=1000, n_features=12, centers=5, shuffle=False, random_state=0
)
Instantiate the clustering model and visualizer
model = GMM(n_components = 5, random_state=0)
visualizer = SilhouetteVisualizer(model, colors='yellowbrick')
visualizer.fit(X) # Fit the data to the visualizer
visualizer.show() # Finalize and render the figure
PLOT
Questions for the @DistrictDataLabs/team-oz-maintainers:
CHECKLIST