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

More flexible KElbow colors that use default palette by default #1172

Closed bbengfort closed 3 years ago

bbengfort commented 3 years ago

Sets the colors in KElbow to cycle colors (C0, C1) to use the default palette rather than hardcoding color codes. Also adds properties so that users can set the metric, timing, and vline colors manually (but not passed in as parameters to init)

This PR fixes #1159

I have made the following changes:

  1. Set constants for the TIMING_COLOR, METRIC_COLOR, both set to cyclic palette colors "C1" and "C0"
  2. Created a colors dictionary on the visualizer and properties to set and access the colors for timing, metric, and vline
  3. Updating the drawing code to use these colors
  4. Created a test for changing colors
  5. Updated test baseline images

Sample Code and Plot

To use the dark background palette in matplotlib:

# Import modeling 
from yellowbrick.cluster import KElbowVisualizer
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans

# Use dark background - must come after YB import
import matplotlib.pyplot as plt
plt.style.use('dark_background')

# Visualize K-Elbow
X, _ = make_blobs()
oz = KElbowVisualizer(KMeans())

oz.fit(X)
oz.show()

t

To set colors manually:

# Import modeling 
from yellowbrick.cluster import KElbowVisualizer
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans

# Visualize K-Elbow
X, _ = make_blobs()
oz = KElbowVisualizer(KMeans())

# Set colors
oz.metric_color = 'r'
oz.timing_color = 'c'
oz.vline_color = 'y'

oz.fit(X)
oz.show()

t

TODOs and questions

No TODOs, all set here!

CHECKLIST

codecov-io commented 3 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (develop@4973ce4). Click here to learn what that means. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop    #1172   +/-   ##
==========================================
  Coverage           ?   90.46%           
==========================================
  Files              ?       90           
  Lines              ?     5065           
  Branches           ?        0           
==========================================
  Hits               ?     4582           
  Misses             ?      483           
  Partials           ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4973ce4...9652160. Read the comment docs.

bbengfort commented 3 years ago

@lwgray no idea how I got the tests to pass ... but they did; so going to merge before I blink and they fail again!