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. As the label may be complex, we calculate different properties of the label and check their distribution.

A label property is any function that gets labels and returns list of values. each value represents a property on the label, such as number of objects in image or tilt of each bounding box in image.

There are default properties per task: For classification: - distribution of classes

For object detection: - distribution of classes - distribution of bounding box areas - distribution of number of bounding boxes per image

For numerical distributions, 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.

Parameters
label_propertiesList[Dict[str, Any]], default: None

List of properties. Replaces the default deepchecks properties. Each property is dictionary with keys ‘name’ (str), ‘method’ (Callable) and ‘output_type’ (str), representing attributes of said method. ‘output_type’ must be one of ‘continuous’/’discrete’/’class_id’

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 discrete properties. Max number of allowed categories. If there are more, they are binned into an “Other” category. If max_num_categories=None, there is no limit. This limit applies for both drift calculation and for 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: “cramers_v” for Cramer’s V, “PSI” for Population Stability Index (PSI).

max_num_categories: int, default: None

Deprecated. Please use max_num_categories_for_drift and max_num_categories_for_display instead

__init__(label_properties: Optional[List[Dict[str, Any]]] = None, 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='cramer_v', max_num_categories: Optional[int] = None, **kwargs)[source]#
__new__(*args, **kwargs)#

Methods

TrainTestLabelDrift.add_condition(name, ...)

Add new condition function to the check.

TrainTestLabelDrift.add_condition_drift_score_not_greater_than([...])

Add condition - require label properties drift score to not be more than a certain threshold.

TrainTestLabelDrift.clean_conditions()

Remove all conditions from this check instance.

TrainTestLabelDrift.compute(context)

Calculate drift on label properties samples that were collected during update() calls.

TrainTestLabelDrift.conditions_decision(result)

Run conditions on given result.

TrainTestLabelDrift.finalize_check_result(...)

Finalize the check result by adding the check instance and processing the conditions.

TrainTestLabelDrift.initialize_run(context)

Initialize run.

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.remove_condition(index)

Remove given condition by index.

TrainTestLabelDrift.run(train_dataset, ...)

Run check.

TrainTestLabelDrift.update(context, batch, ...)

Perform update on batch for train or test properties.

Examples#