def test_timings(self): """ Test the twinx double axes with k-elbow timings """ visualizer = KElbowVisualizer( KMeans(random_state=0), k=5, timings=True ) visualizer.fit(X) # Check that we kept track of time assert len(visualizer.k_timers_) == 4 assert all([t > 0 for t in visualizer.k_timers_]) # Check that we plotted time on a twinx assert hasattr(visualizer, "axes") assert len(visualizer.axes) == 2 # delete the timings axes and # overwrite k_timers_, k_values_ for image similarity Tests visualizer.axes[1].remove() visualizer.k_timers_ = [ 0.01084589958190918, 0.011144161224365234, 0.017028093338012695, 0.010634183883666992 ] visualizer.k_values_ = [2, 3, 4, 5] # call draw again which is normally called in fit visualizer.draw() visualizer.poof() self.assert_images_similar(visualizer)
def test_timings(self): """ Test the twinx double axes with k-elbow timings """ visualizer = KElbowVisualizer(KMeans(random_state=0), k=5, timings=True, locate_elbow=False) visualizer.fit(self.clusters.X) # Check that we kept track of time assert len(visualizer.k_timers_) == 4 assert all([t > 0 for t in visualizer.k_timers_]) # Check that we plotted time on a twinx assert hasattr(visualizer, "axes") assert len(visualizer.axes) == 2 # delete the timings axes and # overwrite k_timers_, k_values_ for image similarity Tests visualizer.axes[1].remove() visualizer.k_timers_ = [ 0.01084589958190918, 0.011144161224365234, 0.017028093338012695, 0.010634183883666992, ] visualizer.k_values_ = [2, 3, 4, 5] # call draw again which is normally called in fit visualizer.draw() visualizer.finalize() self.assert_images_similar(visualizer)
def test_set_colors_manually(self): """ Test the silhouette metric of the k-elbow visualizer """ oz = KElbowVisualizer( KMeans(random_state=0), k=5, ) oz.metric_color = "r" oz.timing_color = "y" oz.vline_color = "c" # Create artificial "fit" data for testing purposes oz.k_values_ = [1, 2, 3, 4, 5, 6, 7, 8] oz.k_timers_ = [6.2, 8.3, 10.1, 15.8, 21.2, 27.9, 38.2, 44.9] oz.k_scores_ = [.8, .7, .55, .48, .40, .38, .35, .30] oz.elbow_value_ = 5 oz.elbow_score_ = 0.40 # Execute drawing oz.draw() oz.finalize() self.assert_images_similar(oz, tol=3.2)