Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self,
ax=None,
fig=None,
features=None,
classes=None,
colors=None,
colormap=None,
target_type="auto",
**kwargs
):
super(DataVisualizer, self).__init__(
ax=ax, fig=fig, features=features, **kwargs
)
# Validate raises YellowbrickValueError if invalid
TargetType.validate(target_type)
# Data Parameters
self.classes = classes
self.target_type = target_type
# Visual Parameters
self.colors = colors
self.colormap = colormap
# Internal attributes
self._colors = None
self._target_color_type = None
self._label_encoder = None
def _determine_target_color_type(self, y):
"""
Determines the target color type from the vector y as follows:
- if y is None: only a single color is used
- if target is auto: determine if y is continuous or discrete
- otherwise specify supplied target type
This property will be used to compute the colors for each point.
"""
if y is None:
self._target_color_type = TargetType.SINGLE
elif self.target_type == TargetType.AUTO:
self._target_color_type = target_color_type(y)
else:
self._target_color_type = TargetType(self.target_type)
# Ensures that target is either SINGLE, DISCRETE or CONTINUOUS before continuing
if (
self._target_color_type == TargetType.AUTO
or self._target_color_type == TargetType.UNKNOWN
):
raise YellowbrickValueError(
(
"could not determine target color type " "from target='{}' to '{}'"
).format(self.target_type, self._target_color_type)
)
scikit-learn supervised estimator.
Returns
-------
color_type : string
One of:
* 'discrete': `y` is either a binary target or a multiclass target
with <= 12 discrete classes.
* 'continuous': `y` is an array-like of floats that are not all
integers or a multiclass target with > 12 discrete classes.
* 'unknown': `y` is array-like but none of the above. For example
a multilabel-indicator or a 3D array. No exception is raised.
"""
if y is None or len(np.unique(y)) == 1:
return TargetType.SINGLE
ttype = type_of_target(y)
if ttype.startswith("continuous"):
return TargetType.CONTINUOUS
if ttype.startswith("binary"):
return TargetType.DISCRETE
if ttype.startswith("multiclass"):
if len(np.unique(y)) > MAX_DISCRETE_CLASSES:
return TargetType.CONTINUOUS
return TargetType.DISCRETE
return TargetType.UNKNOWN
def _determine_target_color_type(self, y):
"""
Determines the target color type from the vector y as follows:
- if y is None: only a single color is used
- if target is auto: determine if y is continuous or discrete
- otherwise specify supplied target type
This property will be used to compute the colors for each point.
"""
if y is None:
self._target_color_type = TargetType.SINGLE
elif self.target_type == TargetType.AUTO:
self._target_color_type = target_color_type(y)
else:
self._target_color_type = TargetType(self.target_type)
# Ensures that target is either SINGLE, DISCRETE or CONTINUOUS before continuing
if (
self._target_color_type == TargetType.AUTO
or self._target_color_type == TargetType.UNKNOWN
):
raise YellowbrickValueError(
(
"could not determine target color type " "from target='{}' to '{}'"
).format(self.target_type, self._target_color_type)
)
One of:
* 'discrete': `y` is either a binary target or a multiclass target
with <= 12 discrete classes.
* 'continuous': `y` is an array-like of floats that are not all
integers or a multiclass target with > 12 discrete classes.
* 'unknown': `y` is array-like but none of the above. For example
a multilabel-indicator or a 3D array. No exception is raised.
"""
if y is None or len(np.unique(y)) == 1:
return TargetType.SINGLE
ttype = type_of_target(y)
if ttype.startswith("continuous"):
return TargetType.CONTINUOUS
if ttype.startswith("binary"):
return TargetType.DISCRETE
if ttype.startswith("multiclass"):
if len(np.unique(y)) > MAX_DISCRETE_CLASSES:
return TargetType.CONTINUOUS
return TargetType.DISCRETE
return TargetType.UNKNOWN
def __eq__(self, other):
if isinstance(other, str):
try:
return TargetType(other.lower()) == self
except ValueError:
return False
return super(TargetType, self).__eq__(other)
with <= 12 discrete classes.
* 'continuous': `y` is an array-like of floats that are not all
integers or a multiclass target with > 12 discrete classes.
* 'unknown': `y` is array-like but none of the above. For example
a multilabel-indicator or a 3D array. No exception is raised.
"""
if y is None or len(np.unique(y)) == 1:
return TargetType.SINGLE
ttype = type_of_target(y)
if ttype.startswith("continuous"):
return TargetType.CONTINUOUS
if ttype.startswith("binary"):
return TargetType.DISCRETE
if ttype.startswith("multiclass"):
if len(np.unique(y)) > MAX_DISCRETE_CLASSES:
return TargetType.CONTINUOUS
return TargetType.DISCRETE
return TargetType.UNKNOWN
return TargetType.SINGLE
ttype = type_of_target(y)
if ttype.startswith("continuous"):
return TargetType.CONTINUOUS
if ttype.startswith("binary"):
return TargetType.DISCRETE
if ttype.startswith("multiclass"):
if len(np.unique(y)) > MAX_DISCRETE_CLASSES:
return TargetType.CONTINUOUS
return TargetType.DISCRETE
return TargetType.UNKNOWN
- if target is auto: determine if y is continuous or discrete
- otherwise specify supplied target type
This property will be used to compute the colors for each point.
"""
if y is None:
self._target_color_type = TargetType.SINGLE
elif self.target_type == TargetType.AUTO:
self._target_color_type = target_color_type(y)
else:
self._target_color_type = TargetType(self.target_type)
# Ensures that target is either SINGLE, DISCRETE or CONTINUOUS before continuing
if (
self._target_color_type == TargetType.AUTO
or self._target_color_type == TargetType.UNKNOWN
):
raise YellowbrickValueError(
(
"could not determine target color type " "from target='{}' to '{}'"
).format(self.target_type, self._target_color_type)
)