def test_palette_cycles(self):
     """
     Test that the color palette cycles for more colors
     """
     accent = color_palette("accent")
     double_accent = color_palette("accent", 12)
     self.assertEqual(double_accent, accent + accent)
Beispiel #2
0
 def test_palette_cycles(self):
     """
     Test that the color palette cycles for more colors
     """
     accent = color_palette("accent")
     double_accent = color_palette("accent", 12)
     self.assertEqual(double_accent, accent + accent)
 def test_preserved_palette_length(self):
     """
     Test palette length is preserved when modified
     """
     pal_in = color_palette("Set1", 10)
     pal_out = color_palette(pal_in)
     self.assertEqual(pal_in, pal_out)
 def test_palette_cycles(self):
     """
     Test that the color palette cycles for more colors
     """
     accent = color_palette("accent")
     double_accent = color_palette("accent", 12)
     assert double_accent == accent + accent
Beispiel #5
0
 def test_preserved_palette_length(self):
     """
     Test palette length is preserved when modified
     """
     pal_in = color_palette("Set1", 10)
     pal_out = color_palette(pal_in)
     self.assertEqual(pal_in, pal_out)
Beispiel #6
0
    def test_bad_palette_name(self):
        """
        Test that a bad palette name raises an exception
        """

        with self.assertRaises(ValueError):
            color_palette("IAmNotAPalette")

        with self.assertRaises(YellowbrickValueError):
            color_palette("IAmNotAPalette")
    def test_bad_palette_name(self):
        """
        Test that a bad palette name raises an exception
        """

        with self.assertRaises(ValueError):
            color_palette("IAmNotAPalette")

        with self.assertRaises(YellowbrickValueError):
            color_palette("IAmNotAPalette")
Beispiel #8
0
    def test_bad_palette_colors(self):
        """
        Test that bad color names raise an exception
        """

        pal = ["red", "blue", "iamnotacolor"]
        with self.assertRaises(ValueError):
            color_palette(pal)

        with self.assertRaises(YellowbrickValueError):
            color_palette(pal)
    def test_bad_palette_colors(self):
        """
        Test that bad color names raise an exception
        """

        pal = ["red", "blue", "iamnotacolor"]
        with self.assertRaises(ValueError):
            color_palette(pal)

        with self.assertRaises(YellowbrickValueError):
            color_palette(pal)
    def test_color_palette_context(self):
        """
        Test ColorPalette context management
        """
        default = color_palette()
        context = color_palette("dark")

        with ColorPalette("dark") as palette:
            assert isinstance(palette, ColorPalette)
            assert get_color_cycle() == context

        assert get_color_cycle() == default
Beispiel #11
0
    def test_palette_context(self):
        """
        Test the context manager for the color_palette function
        """

        default_pal = color_palette()
        context_pal = color_palette("muted")

        with color_palette(context_pal):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), default_pal)
    def test_palette_context(self):
        """
        Test the context manager for the color_palette function
        """

        default_pal = color_palette()
        context_pal = color_palette("muted")

        with color_palette(context_pal):
            assert get_color_cycle() == context_pal

        assert get_color_cycle() == default_pal
    def test_color_palette_context(self):
        """
        Test ColorPalette context management
        """
        default = color_palette()
        context = color_palette('dark')

        with ColorPalette('dark') as palette:
            self.assertIsInstance(palette, ColorPalette)
            self.assertEqual(get_color_cycle(), context)

        self.assertEqual(get_color_cycle(), default)
    def test_palette_context(self):
        """
        Test the context manager for the color_palette function
        """

        default_pal = color_palette()
        context_pal = color_palette("muted")

        with color_palette(context_pal):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), default_pal)
Beispiel #15
0
    def test_color_palette_context(self):
        """
        Test ColorPalette context management
        """
        default = color_palette()
        context = color_palette('dark')

        with ColorPalette('dark') as palette:
            self.assertIsInstance(palette, ColorPalette)
            self.assertEqual(get_color_cycle(), context)

        self.assertEqual(get_color_cycle(), default)
Beispiel #16
0
    def __init__(self,
                 width=0.5,
                 color=None,
                 colors=None,
                 classes=None,
                 **kwargs):

        if "target_type" not in kwargs:
            kwargs["target_type"] = "single"
        super(MissingValuesBar, self).__init__(**kwargs)
        self.width = width  # the width of the bars
        self.classes_ = classes
        self.ind = None

        # Convert to array if necessary to match estimator.classes_
        if self.classes_ is not None:
            self.classes_ = np.array(classes)

        # Set up classifier score visualization properties
        self.color = color
        if self.classes_ is not None:
            n_colors = len(self.classes_)
        else:
            n_colors = None

        self.colors = color_palette(kwargs.pop("colors", None), n_colors)
    def test_big_palette_context(self):
        """
        Test that the context manager also resets the number of colors
        """

        original_pal = color_palette("accent", n_colors=8)
        context_pal = color_palette("bold", 10)

        set_palette(original_pal)
        with color_palette(context_pal, 10):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), original_pal)

        # Reset default
        set_aesthetic()
Beispiel #18
0
    def test_big_palette_context(self):
        """
        Test that the context manager also resets the number of colors
        """

        original_pal = color_palette("accent", n_colors=8)
        context_pal = color_palette("bold", 10)

        set_palette(original_pal)
        with color_palette(context_pal, 10):
            self.assertEqual(get_color_cycle(), context_pal)

        self.assertEqual(get_color_cycle(), original_pal)

        # Reset default
        set_aesthetic()
 def test_yellowbrick_palettes(self):
     """
     Test the yellowbrick palettes have length 6 (bgrmyck)
     """
     pals = ["accent", "dark", "pastel", "bold", "muted"]
     for name in pals:
         pal_out = color_palette(name)
         self.assertEqual(len(pal_out), 6, "{} is not of len 6".format(name))
 def test_other_palettes(self):
     """
     Test that the other palettes exist
     """
     pals = ["flatui", "paired", "neural_paint", "set1"]
     for name in pals:
         pal_out = color_palette(name)
         self.assertTrue(pal_out)
Beispiel #21
0
 def test_other_palettes(self):
     """
     Test that the other palettes exist
     """
     pals = ["flatui", "paired", "neural_paint", "set1"]
     for name in pals:
         pal_out = color_palette(name)
         self.assertTrue(pal_out)
Beispiel #22
0
 def test_yellowbrick_palettes(self):
     """
     Test the yellowbrick palettes have length 6 (bgrmyck)
     """
     pals = ["accent", "dark", "pastel", "bold", "muted"]
     for name in pals:
         pal_out = color_palette(name)
         self.assertEqual(len(pal_out), 6, "{} is not of len 6".format(name))
 def test_other_palettes(self):
     """
     Test that the other palettes exist
     """
     pals = ["flatui", "paired", "neural_paint", "set1"]
     for name in pals:
         pal_out = color_palette(name)
         assert pal_out is not None
         assert len(pal_out) > 0
 def test_seaborn_palettes(self):
     """
     Test the seaborn palettes have length 6 (bgrmyck)
     """
     pals = ["sns_deep", "sns_muted", "sns_pastel",
             "sns_bright", "sns_dark", "sns_colorblind"]
     for name in pals:
         pal_out = color_palette(name)
         self.assertEqual(len(pal_out), 6)
Beispiel #25
0
 def test_seaborn_palettes(self):
     """
     Test the seaborn palettes have length 6 (bgrmyck)
     """
     pals = ["sns_deep", "sns_muted", "sns_pastel",
             "sns_bright", "sns_dark", "sns_colorblind"]
     for name in pals:
         pal_out = color_palette(name)
         self.assertEqual(len(pal_out), 6)
Beispiel #26
0
    def test_as_hex(self):
        """
        Test converting a color palette to hex and back to rgb.
        """
        pal = color_palette("accent")
        for rgb, hex in zip(pal, pal.as_hex()):
            self.assertEqual(mpl.colors.rgb2hex(rgb), hex)

        for rgb_e, rgb_v in zip(pal, pal.as_hex().as_rgb()):
            self.assertEqual(rgb_e, rgb_v)
Beispiel #27
0
    def test_current_palette(self):
        """
        Test modifying the current palette with a simple palette
        """
        pal = color_palette(["red", "blue", "green"], 3)
        set_palette(pal, 3)
        self.assertEqual(pal, get_color_cycle())

        # Reset the palette
        set_aesthetic()
    def test_current_palette(self):
        """
        Test modifying the current palette with a simple palette
        """
        pal = color_palette(["red", "blue", "green"], 3)
        set_palette(pal, 3)
        self.assertEqual(pal, get_color_cycle())

        # Reset the palette
        set_aesthetic()
    def test_as_hex(self):
        """
        Test converting a color palette to hex and back to rgb.
        """
        pal = color_palette("accent")
        for rgb, hex in zip(pal, pal.as_hex()):
            self.assertEqual(mpl.colors.rgb2hex(rgb), hex)

        for rgb_e, rgb_v in zip(pal, pal.as_hex().as_rgb()):
            self.assertEqual(rgb_e, rgb_v)
 def test_color_codes(self):
     """
     Test the setting of color codes
     """
     set_color_codes("accent")
     colors = color_palette("accent") + ["0.06666666666666667"]
     for code, color in zip("bgrmyck", colors):
         rgb_want = mpl.colors.colorConverter.to_rgb(color)
         rgb_got = mpl.colors.colorConverter.to_rgb(code)
         self.assertEqual(rgb_want, rgb_got)
     set_color_codes("reset")
Beispiel #31
0
 def test_color_codes(self):
     """
     Test the setting of color codes
     """
     set_color_codes("accent")
     colors = color_palette("accent") + ["0.06666666666666667"]
     for code, color in zip("bgrmyck", colors):
         rgb_want = mpl.colors.colorConverter.to_rgb(color)
         rgb_got = mpl.colors.colorConverter.to_rgb(code)
         self.assertEqual(rgb_want, rgb_got)
     set_color_codes("reset")
Beispiel #32
0
    def test_palette_is_list_of_tuples(self):
        """
        Assert that color_palette returns a list of RGB tuples
        """

        pal_in = np.array(["red", "blue", "green"])
        pal_out = color_palette(pal_in, 3)

        self.assertIsInstance(pal_out, list)
        self.assertIsInstance(pal_out[0], tuple)
        self.assertIsInstance(pal_out[0][0], float)
        self.assertEqual(len(pal_out[0]), 3)
    def test_palette_is_list_of_tuples(self):
        """
        Assert that color_palette returns a list of RGB tuples
        """

        pal_in = np.array(["red", "blue", "green"])
        pal_out = color_palette(pal_in, 3)

        self.assertIsInstance(pal_out, list)
        self.assertIsInstance(pal_out[0], tuple)
        self.assertIsInstance(pal_out[0][0], float)
        self.assertEqual(len(pal_out[0]), 3)
    def test_as_hex_as_rgb(self):
        """
        Test the conversion of a ColorPalette to hex values and back to rgb
        """
        palette   = color_palette('flatui')
        expected  = PALETTES['flatui']
        morgified = palette.as_hex()

        self.assertIsNot(morgified, palette)
        self.assertIsInstance(morgified, ColorPalette)
        self.assertEqual(morgified, expected)

        remorgified = morgified.as_rgb()
        self.assertIsNot(remorgified, morgified)
        self.assertIsNot(remorgified, palette)
        self.assertEqual(remorgified, palette)
    def test_as_hex_as_rgb(self):
        """
        Test the conversion of a ColorPalette to hex values and back to rgb
        """
        palette = color_palette("flatui")
        expected = PALETTES["flatui"]
        morgified = palette.as_hex()

        assert morgified is not palette
        assert isinstance(morgified, ColorPalette)
        assert morgified == expected

        remorgified = morgified.as_rgb()
        assert remorgified is not morgified
        assert remorgified is not palette
        assert remorgified == palette
Beispiel #36
0
    def test_as_hex_as_rgb(self):
        """
        Test the conversion of a ColorPalette to hex values and back to rgb
        """
        palette   = color_palette('flatui')
        expected  = PALETTES['flatui']
        morgified = palette.as_hex()

        self.assertIsNot(morgified, palette)
        self.assertIsInstance(morgified, ColorPalette)
        self.assertEqual(morgified, expected)

        remorgified = morgified.as_rgb()
        self.assertIsNot(remorgified, morgified)
        self.assertIsNot(remorgified, palette)
        self.assertEqual(remorgified, palette)
Beispiel #37
0
    def __init__(self, width=0.5, color='black', colors=None, classes=None, **kwargs):
        super(MissingValuesBar, self).__init__(**kwargs)
        self.width = width  # the width of the bars
        self.classes_ = classes
        self.ind = None

        # Convert to array if necessary to match estimator.classes_
        if self.classes_ is not None:
            self.classes_ = np.array(classes)

        # Set up classifier score visualization properties
        if self.classes_ is not None:
            n_colors = len(self.classes_)
        else:
            n_colors = None

        self.colors = color_palette(kwargs.pop('colors', None), n_colors)
    def __init__(self, alpha=0.5, marker="|", classes=None, **kwargs):

        super(MissingValuesDispersion, self).__init__(**kwargs)
        self.alpha = alpha
        self.marker = marker

        self.classes_ = classes

        # Convert to array if necessary to match estimator.classes_
        if self.classes_ is not None:
            self.classes_ = np.array(classes)

        # Set up classifier score visualization properties
        if self.classes_ is not None:
            n_colors = len(self.classes_)
        else:
            n_colors = None

        self.colors = color_palette(kwargs.pop('colors', None), n_colors)
Beispiel #39
0
    def __init__(self, alpha=0.5, marker="|", classes=None, **kwargs):

        super(MissingValuesDispersion, self).__init__(**kwargs)
        self.alpha = alpha
        self.marker = marker

        self.classes_ = classes

        # Convert to array if necessary to match estimator.classes_
        if self.classes_ is not None:
            self.classes_ = np.array(classes)

        # Set up classifier score visualization properties
        if self.classes_ is not None:
            n_colors = len(self.classes_)
        else:
            n_colors = None

        self.colors = color_palette(kwargs.pop('colors', None), n_colors)
Beispiel #40
0
    def class_colors_(self):
        """
        Returns ``_colors`` if it exists, otherwise computes a categorical color
        per class based on the matplotlib color cycle. If the visualizer is not
        fitted, raises a NotFitted exception.

        If subclasses require users to choose colors or have specialized color
        handling, they should set ``_colors`` on init or during fit.

        Notes
        -----
        Because this is a property, this docstring is for developers only.
        """
        if not hasattr(self, "_colors"):
            if not hasattr(self, "classes_"):
                raise NotFitted("cannot determine colors before fit")

            # TODO: replace with resolve_colors
            self._colors = color_palette(None, len(self.classes_))
        return self._colors
plt.show()

# summarize history for loss
plt.plot(accuracy_history_test)
plt.title('model accuracy')
plt.ylabel('loss')
plt.xlabel("500th iteration")
plt.legend(['test'], loc='upper left')
plt.savefig("accuracy history.png")
plt.show()

from yellowbrick.features.pca import PCADecomposition
from yellowbrick.style.palettes import PALETTES, SEQUENCES, color_palette

# get color for all classes
pallette = color_palette("reset")
colors = list(map(lambda idx: pallette[idx // test_set.shape[1]], range(len(pred_test))))

visualizer = PCADecomposition(scale=True, proj_dim=3, color = colors, size=(1080, 720))
visualizer.fit_transform(pred_test, colors)
visualizer.poof(outpath="./pca", dpi=300)

def plot_confusion_matrix(cm, classes,
                          normalize=False,
                          title='Confusion matrix',
                          cmap=plt.cm.Blues):
    """
    This function prints and plots the confusion matrix.
    Normalization can be applied by setting `normalize=True`.
    """
    if normalize:
Beispiel #42
0
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
from sklearn.pipeline import Pipeline
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
import statsmodels.api as sm

from imblearn.over_sampling import SMOTE
from collections import Counter

from yellowbrick.classifier import ROCAUC
from yellowbrick.classifier import ConfusionMatrix
from yellowbrick.classifier import ClassificationReport
from yellowbrick.style.palettes import PALETTES, SEQUENCES, color_palette
color_palette(palette='flatui', n_colors=8)
from yellowbrick.style import set_palette
set_palette('pastel')

pd.set_option('display.max_colwidth', -1)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
sns.set_context('talk')
sns.set_style('ticks')
sns.set_palette('RdBu')
np.random.seed(42)

import warnings 
warnings.filterwarnings('ignore')

    topic = labels[i]
    if topic >= 0:
        prob_matrix[i][topic] = probabilities[i]


'''
# t-SNE: 50 -> 2D
tsne_model = TSNE(n_components=2, verbose=1, random_state=0, angle=.5,
                    init='pca')

tsne_lda = tsne_model.fit_transform(prob_matrix)
'''


palette = sns.color_palette('deep', np.unique(labels).max() + 1)
palette2 = color_palette('bold', np.unique(labels).max() + 1)
mycolors = [palette[x] if x >= 0.0 else (0.0, 0.0, 0.0) for x in labels]
'''
plt.scatter(tsne_lda[:,0], tsne_lda[:,1], c=colors)
frame = plt.gca()
frame.axes.get_xaxis().set_visible(False)
frame.axes.get_yaxis().set_visible(False)
plt.show()
'''


colormap =  []
big_colormap = []

mycolormap = yellowbrick.style.colors.resolve_colors(n_colors=n_topics+1, colormap=None, colors=None)