Implementation:DistrictDataLabs Yellowbrick TargetType Utilities
| Knowledge Sources | |
|---|---|
| Domains | Data_Science, Utilities |
| Last Updated | 2026-02-08 05:00 GMT |
Overview
Target variable type detection utilities providing the TargetType enum and automatic classification of target vectors as single, discrete, or continuous.
Description
The utils.target module provides the TargetType enum with values AUTO, SINGLE, DISCRETE, CONTINUOUS, and UNKNOWN, and the target_color_type function that inspects a target vector to determine its type. This determines whether Yellowbrick visualizers use discrete class colors or a continuous colormap. The threshold for discrete vs continuous is MAX_DISCRETE_CLASSES = 12.
Usage
Import these utilities when building visualizers that need to auto-detect whether to use a categorical or continuous color scheme based on the target variable.
Code Reference
Source Location
- Repository: DistrictDataLabs_Yellowbrick
- File: yellowbrick/utils/target.py
- Lines: 1-106
Signature
class TargetType(Enum):
AUTO = "auto"
SINGLE = "single"
DISCRETE = "discrete"
CONTINUOUS = "continuous"
UNKNOWN = "unknown"
@classmethod
def validate(klass, val): ...
def target_color_type(y):
"""Determines the TargetType for a target vector."""
Import
from yellowbrick.utils.target import TargetType, target_color_type
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| y | array-like | Yes | Target vector to classify |
Outputs
| Name | Type | Description |
|---|---|---|
| target_type | TargetType | SINGLE, DISCRETE, CONTINUOUS, or UNKNOWN |
Usage Examples
import numpy as np
from yellowbrick.utils.target import target_color_type, TargetType
# Discrete target
y_cls = np.array([0, 1, 2, 0, 1, 2])
print(target_color_type(y_cls)) # TargetType.DISCRETE
# Continuous target
y_reg = np.random.randn(100)
print(target_color_type(y_reg)) # TargetType.CONTINUOUS
# Single value
y_single = None
print(target_color_type(y_single)) # TargetType.SINGLE