TrainTestPredictionDrift#

class TrainTestPredictionDrift[source]#

Calculate prediction drift between train dataset and test dataset, using statistical measures.

Check calculates a drift score for the prediction in the test dataset, by comparing its distribution to the train dataset. For classification tasks, by default the drift score will be computed on the predicted probability of the positive (1) class for binary classification tasks, and on the predicted class itself for multiclass tasks. This behavior can be controlled using the drift_mode parameter.

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 predictions, 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
drift_mode: str, default: ‘auto’

For classification task, controls whether to compute drift on the predicted probabilities or the predicted classes. For regression task this parameter may be ignored. If set to ‘auto’, compute drift on the predicted class if the task is multiclass, and on the predicted probability of the positive class if binary. Set to ‘proba’ to force drift on the predicted probabilities, and ‘prediction’ to force drift on the predicted classes. If set to ‘proba’, on a multiclass task, drift would be calculated on each class independently.

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.

max_num_categories_for_drift: int, default: 10

Only for categorical columns. Max number of allowed categories. If there are more, they are binned into an “Other” category. If None, there is no limit.

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.

aggregation_method: str, default: “max”

Argument for the reduce_output functionality, decides how to aggregate the drift scores of different classes (for classification tasks) into a single score, when drift is computed on the class probabilities. Possible values are: ‘max’: Maximum of all the class drift scores. ‘weighted’: Weighted mean based on the class sizes in the train data set. ‘mean’: Mean of all drift scores. ‘none’: No averaging. Return a dict with a drift score for each class.

max_classes_to_display: int, default: 3

Max number of classes to show in the display when drift is computed on the class probabilities for classification tasks.

max_num_categories: int, default: None

Deprecated. Please use max_num_categories_for_drift and max_num_categories_for_display instead

__init__(drift_mode: str = 'auto', margin_quantile_filter: float = 0.025, max_num_categories_for_drift: int = 10, max_num_categories_for_display: int = 10, show_categories_by: str = 'largest_difference', categorical_drift_method: str = 'cramer_v', ignore_na: bool = True, aggregation_method: str = 'max', max_classes_to_display: int = 3, max_num_categories: Optional[int] = None, **kwargs)[source]#
__new__(*args, **kwargs)#

Methods

TrainTestPredictionDrift.add_condition(name, ...)

Add new condition function to the check.

TrainTestPredictionDrift.add_condition_drift_score_less_than([...])

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

TrainTestPredictionDrift.clean_conditions()

Remove all conditions from this check instance.

TrainTestPredictionDrift.conditions_decision(result)

Run conditions on given result.

TrainTestPredictionDrift.config()

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

TrainTestPredictionDrift.from_config(conf)

Return check object from a CheckConfig object.

TrainTestPredictionDrift.metadata([...])

Return check metadata.

TrainTestPredictionDrift.name()

Name of class in split camel case.

TrainTestPredictionDrift.params([show_defaults])

Return parameters to show when printing the check.

TrainTestPredictionDrift.reduce_output(...)

Return prediction drift score.

TrainTestPredictionDrift.remove_condition(index)

Remove given condition by index.

TrainTestPredictionDrift.run(train_dataset, ...)

Run check.

TrainTestPredictionDrift.run_logic(context)

Calculate drift for all columns.

Examples#