LabelDrift#
- class LabelDrift[source]#
Calculate label drift between train dataset and test dataset, using statistical measures.
Check calculates a drift score for the label in test dataset, by comparing its distribution to the train dataset.
For categorical distributions, we use the Cramer’s V. See https://en.wikipedia.org/wiki/Cram%C3%A9r%27s_V We also support Population Stability Index (PSI). See https://www.lexjansen.com/wuss/2017/47_Final_Paper_PDF.pdf.
For categorical labels, it is recommended to use Cramer’s V, unless your variable includes categories with a small number of samples (common practice is categories with less than 5 samples). However, in cases of a variable with many categories with few samples, it is still recommended to use Cramer’s V.
Note: In case of highly imbalanced classes, it is recommended to use Cramer’s V, together with setting the
balance_classes
parameter toTrue
.- Parameters
- min_category_size_ratio: float, default 0.01
minimum size ratio for categories. Categories with size ratio lower than this number are binned into an “Other” category. Ignored if balance_classes=True.
- max_num_categories_for_drift: int, default: None
Only for classification. Max number of allowed categories. If there are more, they are binned into an “Other” category.
- max_num_categories_for_display: int, default: 10
Max number of categories to show in plot.
- show_categories_by: str, default: ‘largest_difference’
Specify which categories to show for categorical features’ graphs, as the number of shown categories is limited by max_num_categories_for_display. Possible values: - ‘train_largest’: Show the largest train categories. - ‘test_largest’: Show the largest test categories. - ‘largest_difference’: Show the largest difference between categories.
- categorical_drift_method: str, default: “cramers_v”
decides which method to use on categorical variables. Possible values are: “cramers_v” for Cramer’s V, “PSI” for Population Stability Index (PSI).
- balance_classes: bool, default: False
If True, all categories will have an equal weight in the Cramer’s V score. This is useful when the categorical variable is highly imbalanced, and we want to be alerted on changes in proportion to the category size, and not only to the entire dataset. Must have categorical_drift_method = “cramers_v”. If True, the variable frequency plot will be created with a log scale in the y-axis.
- ignore_na: bool, default False
For categorical columns only. If True, ignores nones for categorical drift. If False, considers none as a separate category. For numerical columns we always ignore nones.
- min_samplesint , default: 10
Minimum number of samples required to calculate the drift score. If there are not enough samples for either train or test, the check will raise a
NotEnoughSamplesError
exception.- n_samplesint , default: 100_000
Number of samples to use for drift computation and plot.
- random_stateint , default: 42
Random seed for sampling.
- __init__(max_num_categories_for_drift: Optional[int] = None, min_category_size_ratio: float = 0.01, max_num_categories_for_display: int = 10, show_categories_by: str = 'largest_difference', categorical_drift_method: str = 'cramers_v', balance_classes: bool = False, ignore_na: bool = False, min_samples: int = 10, n_samples: int = 100000, random_state: int = 42, **kwargs)[source]#
- __new__(*args, **kwargs)#
Attributes
Methods
|
Add new condition function to the check. |
Add condition - require drift score to be less than the threshold. |
|
Remove all conditions from this check instance. |
|
|
Run conditions on given result. |
|
Return check configuration (conditions' configuration not yet supported). |
|
Return check object from a CheckConfig object. |
|
Deserialize check instance from JSON string. |
|
Return check metadata. |
Name of class in split camel case. |
|
|
Return parameters to show when printing the check. |
|
Remove given condition by index. |
|
Run check. |
|
Calculate drift for all columns. |
|
Serialize check instance to JSON string. |