Skip to content

Commit

Permalink
hoisted ax to Visualizer base class and model name to ScoreVisualizer…
Browse files Browse the repository at this point in the history
… base class, closes #62
  • Loading branch information
rebeccabilbro committed Oct 30, 2016
1 parent ba14a4f commit 5f7ab81
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
3 changes: 3 additions & 0 deletions yellowbrick/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Visualizer(BaseEstimator):
"""

def __init__(self, **kwargs):
self.ax = None

This comment has been minimized.

Copy link
@bbengfort

bbengfort Oct 30, 2016

Member

@rebeccabilbro so in order to make sure that we can draw on axes specified by the user we need to pass ax to the constructor:

def __init__(self, ax=None, **kwargs):
    self.ax = ax 

This constructor signature needs to go all the way down for all the base classes.

self.size = kwargs.pop('size', None)
self.color = kwargs.pop('color', None)

Expand Down Expand Up @@ -89,6 +90,8 @@ def __init__(self, model, **kwargs):
self.estimator = model
super(ScoreVisualizer, self).__init__(**kwargs)

self.name = get_model_name(self.estimator)

def fit(self, X, y=None, **kwargs):
self.estimator.fit(X, y, **kwargs)
return self
Expand Down
31 changes: 19 additions & 12 deletions yellowbrick/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, model, **kwargs):

super(ClassificationScoreVisualizer, self).__init__(model, **kwargs)


##########################################################################
## Classification Report
##########################################################################
Expand Down Expand Up @@ -86,11 +87,13 @@ def __init__(self, model, classes=None, **kwargs):
"""
super(ClassificationReport, self).__init__(model, **kwargs)

# TODO: hoist
self.estimator = model
self.ax = None
## hoisted to Visualizer base class
# self.ax = None

## hoisted to ScoreVisualizer base class
# self.estimator = model
# self.name = get_model_name(self.estimator)

self.name = get_model_name(self.estimator)
self.cmap = kwargs.pop('cmap', ddlheatmap)
self.classes_ = classes

Expand Down Expand Up @@ -220,9 +223,11 @@ def __init__(self, model, **kwargs):
"""
super(ROCAUC, self).__init__(model, **kwargs)

# TODO hoist to main
self.name = get_model_name(self.estimator)
self.ax = None
## hoisted to Visualizer base class
# self.ax = None

## hoisted to ScoreVisualizer base class
# self.name = get_model_name(self.estimator)

# TODO refactor to use new Yellowbrick color utils
self.colors = {
Expand Down Expand Up @@ -343,11 +348,13 @@ def __init__(self, model, classes=None, **kwargs):
"""
super(ClassBalance, self).__init__(model, **kwargs)

# TODO: hoist
self.estimator = model
self.ax = None
## hoisted to Visualizer base class
# self.ax = None

## hoisted to ScoreVisualizer base class
# self.estimator = model
# self.name = get_model_name(self.estimator)

self.name = get_model_name(self.estimator)
self.colors = kwargs.pop('colors', YELLOWBRICK_PALETTES['paired'])
self.classes_ = classes

Expand Down Expand Up @@ -387,7 +394,7 @@ def score(self, X, y=None, **kwargs):
y : ndarray or Series of length n
An array or series of target or class values
Returns
------
Expand Down
5 changes: 3 additions & 2 deletions yellowbrick/features/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def __init__(self, ax=None, **kwargs):
super(FeatureVisualizer, self).__init__(**kwargs)

# The figure params
# TODO: hoist to a higher level base class
self.ax = ax

## hoisted to Visualizer base class
# self.ax = ax

def fit(self, X, y=None, **fit_params):
"""
Expand Down
17 changes: 12 additions & 5 deletions yellowbrick/regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ def __init__(self, model, **kwargs):

super(PredictionError, self).__init__(model, **kwargs)

self.ax = None
self.name = get_model_name(self.estimator)
## hoisted to Visualizer base class
# self.ax = None

## hoisted to ScoreVisualizer
# self.name = get_model_name(self.estimator)

self.colors = {
'point': kwargs.pop('point_color', '#F2BE2C'),
'line': kwargs.pop('line_color', '#2B94E9'),
Expand Down Expand Up @@ -193,8 +197,11 @@ def __init__(self, model, **kwargs):

super(ResidualsPlot, self).__init__(model, **kwargs)

self.ax = None
self.name = get_model_name(self.estimator)
## hoisted to Visualizer base class
# self.ax = None

## hoisted to ScoreVisualizer
# self.name = get_model_name(self.estimator)

# TODO Is there a better way to differentiate between train and test points?
# We'd like to color them differently in draw...
Expand Down Expand Up @@ -284,7 +291,7 @@ def draw(self, y_pred, residuals, train=False, **kwargs):

def poof(self):
"""
Returns
------
Expand Down

0 comments on commit 5f7ab81

Please sign in to comment.