nannyml.drift.univariate.result module

Contains the results of the univariate drift calculator and provides plotting functionality.

class nannyml.drift.univariate.result.Result(results_data: DataFrame, column_names: List[str], categorical_column_names: List[str], continuous_column_names: List[str], categorical_method_names: List[str], continuous_method_names: List[str], timestamp_column_name: Optional[str], chunker: Chunker, analysis_data: Optional[DataFrame] = None, reference_data: Optional[DataFrame] = None)[source]

Bases: PerMetricPerColumnResult[Method], ResultCompareMixin

Class wrapping the results of the univariate drift calculator and providing plotting functionality.

  • results_data (pd.DataFrame) – Results data returned by a DataReconstructionDriftCalculator.

  • column_names (List[str]) – A list of column names indicating which columns contain feature values.

  • categorical_column_names (List[str]) – Subset of categorical features to be included in calculation.

  • continuous_column_names (List[str]) – Subset of continuous features to be included in calculation.

  • categorical_method_names (List[str]) –

    A list of method names that will be performed on categorical columns. Supported methods for categorical variables:

    • jensen_shannon

    • chi2

    • hellinger

    • l_infinity

  • continuous_method_names (List[str]) –

    A list of method names that will be performed on continuous columns. Supported methods for continuous variables:

    • jensen_shannon

    • kolmogorov_smirnov

    • hellinger

    • wasserstein

  • timestamp_column_name (Optional[str], default=None) – The name of the column containing the timestamp of the model prediction. If not given, plots will not use a time-based x-axis but will use the index of the chunks instead.

  • chunker (Chunker) – The Chunker used to split the data sets into a lists of chunks.

  • analysis_data (pd.DataFrame, default= None) – Portion of data that NannyML will use to calculate the observed drift.

  • reference_data (pd.DataFrame, default = None) – Portion of data that NannyML will use to fit its drift methods.

keys() List[Key][source]

Creates a list of keys for continuos and categorial columns where each Key is a namedtuple(‘Key’, ‘properties display_names’)

property methods: List[Method]
plot(kind: str = 'drift', *args, **kwargs) Figure[source]

Renders plots for metrics returned by the univariate distance drift calculator.

For any feature you can render the statistic value or p-values as a step plot, or create a distribution plot.


kind (str, default='drift') –

The kind of plot you want to have. Allowed values are:

  • ’drift’

    plots drift per Chunk for a single feature of a chunked data set.

  • ’distribution’

    plots feature distribution per Chunk. Joyplot for continuous features, stacked bar charts for categorical features.


fig – A Figure object containing the requested drift plot.

Can be saved to disk using the write_image() method or shown rendered on screen using the show() method.

Return type:



>>> import nannyml as nml
>>> reference, analysis, _ = nml.load_synthetic_car_price_dataset()
>>> column_names = [col for col in reference.columns if col not in ['timestamp', 'y_pred', 'y_true']]
>>> calc = nml.UnivariateDriftCalculator(
...   column_names=column_names,
...   timestamp_column_name='timestamp',
...   continuous_methods=['kolmogorov_smirnov', 'jensen_shannon', 'wasserstein'],
...   categorical_methods=['chi2', 'jensen_shannon', 'l_infinity'],
... ).fit(reference)
>>> res = calc.calculate(analysis)
>>> res = res.filter(period='analysis')
>>> for column_name in res.continuous_column_names:
...  for method in res.continuous_method_names:
...    res.plot(kind='drift', column_name=column_name, method=method).show()