TrainTestLabelDrift#

class TrainTestLabelDrift[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 numerical columns, we use the Earth Movers Distance. See https://en.wikipedia.org/wiki/Wasserstein_metric

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.

Parameters
margin_quantile_filter: float, default: 0.025

float in range [0,0.5), representing which margins (high and low quantiles) of the distribution will be filtered out of the EMD calculation. This is done in order for extreme values not to affect the calculation disproportionally. This filter is applied to both distributions, in both margins.

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.

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. This limit applies for both drift calculation and distribution plots

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: “cramer_v”

decides which method to use on categorical variables. Possible values are: “cramer_v” for Cramer’s V, “PSI” for Population Stability Index (PSI).

ignore_na: bool, default True

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.

n_samplesint , default: 100_000

Number of samples to use for drift computation and plot.

random_stateint , default: 42

Random seed for sampling.

__init__(margin_quantile_filter: float = 0.025, 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='cramer_v', ignore_na: bool = True, n_samples: int = 100000, random_state: int = 42, **kwargs)[source]#
__new__(*args, **kwargs)#

Methods

TrainTestLabelDrift.add_condition(name, ...)

Add new condition function to the check.

TrainTestLabelDrift.add_condition_drift_score_less_than([...])

Add condition - require drift score to be less than the threshold.

TrainTestLabelDrift.clean_conditions()

Remove all conditions from this check instance.

TrainTestLabelDrift.conditions_decision(result)

Run conditions on given result.

TrainTestLabelDrift.config([include_version])

Return check configuration (conditions' configuration not yet supported).

TrainTestLabelDrift.from_config(conf[, ...])

Return check object from a CheckConfig object.

TrainTestLabelDrift.from_json(conf[, ...])

Deserialize check instance from JSON string.

TrainTestLabelDrift.metadata([with_doc_link])

Return check metadata.

TrainTestLabelDrift.name()

Name of class in split camel case.

TrainTestLabelDrift.params([show_defaults])

Return parameters to show when printing the check.

TrainTestLabelDrift.reduce_output(check_result)

Return label drift score.

TrainTestLabelDrift.remove_condition(index)

Remove given condition by index.

TrainTestLabelDrift.run(train_dataset, ...)

Run check.

TrainTestLabelDrift.run_logic(context)

Calculate drift for all columns.

TrainTestLabelDrift.to_json([indent])

Serialize check instance to JSON string.

Examples#