def test_colormap_as_colors_silhouette(self): """ Test no exceptions for modifying the colors in a silhouette visualizer by using a matplotlib colormap as colors """ # Generate a blobs data set X, y = make_blobs(n_samples=1000, n_features=12, centers=8, shuffle=False, random_state=0) try: fig = plt.figure() ax = fig.add_subplot() visualizer = SilhouetteVisualizer(MiniBatchKMeans(random_state=0), ax=ax, colors="cool") visualizer.fit(X) visualizer.finalize() tol = (3.2 if sys.platform == "win32" else 0.01 ) # Fails on AppVeyor with RMS 3.143 self.assert_images_similar(visualizer, remove_legend=True, tol=tol) except Exception as e: self.fail("error during silhouette: {}".format(e))
def test_integrated_mini_batch_kmeans_silhouette(self): """ Test no exceptions for mini-batch kmeans silhouette visualizer """ # NOTE see #182: cannot use occupancy dataset because of memory usage # Generate a blobs data set X, y = make_blobs(n_samples=1000, n_features=12, centers=8, shuffle=False, random_state=0) try: fig = plt.figure() ax = fig.add_subplot() visualizer = SilhouetteVisualizer(MiniBatchKMeans(random_state=0), ax=ax) visualizer.fit(X) visualizer.finalize() self.assert_images_similar(visualizer, remove_legend=True) except Exception as e: self.fail("error during silhouette: {}".format(e))
def test_colors_silhouette(self): """ Test no exceptions for modifying the colors in a silhouette visualizer with a list of color names """ # Generate a blobs data set X, y = make_blobs(n_samples=1000, n_features=12, centers=8, shuffle=False, random_state=0) try: fig = plt.figure() ax = fig.add_subplot() visualizer = SilhouetteVisualizer( MiniBatchKMeans(random_state=0), ax=ax, colors=["red", "green", "blue", "indigo", "cyan", "lavender"], ) visualizer.fit(X) visualizer.finalize() self.assert_images_similar(visualizer, remove_legend=True) except Exception as e: self.fail("error during silhouette: {}".format(e))
def test_integrated_yb_colormap(self): """ Assert silhouette plot colormap can be set with a yellowbrick palette """ # Generate a blobs data set X, y = make_blobs(n_samples=1000, n_features=12, centers=8, shuffle=False, random_state=0) visualizer = SilhouetteVisualizer(KMeans(random_state=0), colormap="neural_paint") visualizer.fit(X) visualizer.finalize() tol = (3.2 if sys.platform == "win32" else 0.01 ) # Fails on AppVeyor with RMS 3.143 self.assert_images_similar(visualizer, remove_legend=True, tol=tol)