Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
accepts a third dimension, target, which is used to specify the colors
of each of the points. If the target is not specified, then the points
are plotted as a single cloud to show similar documents.
"""
# Resolve the labels with the classes
labels = self.labels if self.labels is not None else self.classes_
if len(labels) != len(self.classes_):
raise YellowbrickValueError(
(
"number of supplied labels ({}) does not "
"match the number of classes ({})"
).format(len(labels), len(self.classes_))
)
# Create the color mapping for the labels.
self.color_values_ = resolve_colors(
n_colors=len(labels), colormap=self.colormap, colors=self.colors
)
colors = dict(zip(labels, self.color_values_))
# Transform labels into a map of class to label
labels = dict(zip(self.classes_, labels))
# Expand the points into vectors of x and y for scatter plotting,
# assigning them to their label if the label has been passed in.
# Additionally, filter classes not specified directly by the user.
series = defaultdict(lambda: {"x": [], "y": []})
if target is not None:
for t, point in zip(target, points):
label = labels[t]
series[label]["x"].append(point[0])
def draw(self):
"""
Draws the cv scores as a line chart on the current axes.
"""
# Set the colors from the supplied values or reasonable defaults
color_values = resolve_colors(n_colors=4, colors=self.color)
for idx, metric in enumerate(METRICS):
# Skip any excluded labels
if metric not in self.cv_scores_:
continue
# Get the color ensuring every metric has a static color
color = color_values[idx]
# Make the label pretty
if metric == "fscore":
if self.fbeta == 1.0:
label = "$f_1$"
else:
label = "$f_{{\beta={:0.1f}}}".format(self.fbeta)
else:
pos_tag_sum = np.sum(pos_tag_counts, axis=0)
if self.frequency:
# sorts the count and tags by sum for frequency true
idx = (pos_tag_sum).argsort()[::-1]
self._pos_tags = np.array(self._pos_tags)[idx]
pos_tag_counts = pos_tag_counts[:,idx]
if self.stack:
bar_stack(
pos_tag_counts, ax=self.ax, labels=list(self.labels_),
ticks=self._pos_tags, colors=self.colors, colormap=self.colormap
)
else:
xidx = np.arange(len(self._pos_tags))
colors = resolve_colors(
n_colors=len(self._pos_tags), colormap=self.colormap,
colors=self.colors
)
self.ax.bar(
xidx, pos_tag_counts[0], color=colors
)
return self.ax
def draw(self, X, y=None, **kwargs):
"""
Called from the fit method, this method creates a decision boundary
plot, and if self.scatter is True, it will scatter plot that draws
each instance as a class or target colored point, whose location
is determined by the feature data set.
"""
# ensure that if someone is passing in another X such as X_test, that
# features will be properly handled
X = self._select_feature_columns(X)
color_cycle = iter(
resolve_colors(colors=self.colors, n_colors=len(self.classes_)))
colors = OrderedDict([(c, next(color_cycle))
for c in self.classes_.keys()])
self.ax.pcolormesh(
self.xx,
self.yy,
self.Z_shape,
alpha=self.pcolormesh_alpha,
cmap=ListedColormap(colors.values()))
# Create a data structure to hold the scatter plot representations
to_plot = OrderedDict()
for index in self.classes_.values():
to_plot[index] = [[], []]
# Add each row of the data set to to_plot for plotting
accepts a third dimension, target, which is used to specify the colors
of each of the points. If the target is not specified, then the points
are plotted as a single cloud to show similar documents.
"""
# Resolve the labels with the classes
labels = self.labels if self.labels is not None else self.classes_
if len(labels) != len(self.classes_):
raise YellowbrickValueError(
(
"number of supplied labels ({}) does not "
"match the number of classes ({})"
).format(len(labels), len(self.classes_))
)
# Create the color mapping for the labels.
self.color_values_ = resolve_colors(
n_colors=len(labels), colormap=self.colormap, colors=self.colors
)
colors = dict(zip(labels, self.color_values_))
# Transform labels into a map of class to label
labels = dict(zip(self.classes_, labels))
# Expand the points into vectors of x and y for scatter plotting,
# assigning them to their label if the label has been passed in.
# Additionally, filter classes not specified directly by the user.
series = defaultdict(lambda: {"x": [], "y": []})
if target is not None:
for t, point in zip(target, points):
label = labels[t]
series[label]["x"].append(point[0])
def draw(self, X, y, **kwargs):
"""Called from the fit method, this method creates a scatter plot that
draws each instance as a class or target colored point, whose location
is determined by the feature data set.
"""
# Set the axes limits
self.ax.set_xlim([-1,1])
self.ax.set_ylim([-1,1])
# set the colors
color_values = resolve_colors(
n_colors=len(self.classes_),
colormap=self.colormap,
colors=self.color
)
colors = dict(zip(self.classes_, color_values))
# Create a data structure to hold the scatter plot representations
to_plot = {}
for kls in self.classes_:
to_plot[kls] = [[], []]
# Add each row of the data set to to_plot for plotting
# TODO: make this an independent function for override
for i, row in enumerate(X):
row_ = np.repeat(np.expand_dims(row, axis=1), 2, axis=1)
def draw(self, **kwargs):
"""
Draws the feature importances as a bar chart; called from fit.
"""
# Quick validation
for param in ("feature_importances_", "features_"):
if not hasattr(self, param):
raise NotFitted("missing required param '{}'".format(param))
# Find the positions for each bar
pos = np.arange(self.features_.shape[0]) + 0.5
# Plot the bar chart
if self.stack:
colors = resolve_colors(len(self.classes_), colormap=self.colormap)
legend_kws = {"bbox_to_anchor": (1.04, 0.5), "loc": "center left"}
bar_stack(
self.feature_importances_,
ax=self.ax,
labels=list(self.classes_),
ticks=self.features_,
orientation="h",
colors=colors,
legend_kws=legend_kws,
)
else:
colors = resolve_colors(
len(self.features_), colormap=self.colormap, colors=self.colors
)
self.ax.barh(pos, self.feature_importances_, color=colors, align="center")