nannyml.drift.target.target_distribution.result module

The classes representing the results of a target distribution calculation.

class nannyml.drift.target.target_distribution.result.TargetDistributionResult(results_data: DataFrame, calculator: AbstractCalculator)[source]

Bases: AbstractCalculatorResult

Contains target distribution data and utilities to plot it.

Creates a new instance of the TargetDistributionResults.

property calculator_name: str
plot(kind: str = 'target_drift', plot_reference: bool = False, *args, **kwargs) Optional[Figure][source]

Renders plots for metrics returned by the target distribution calculator.

You can render a step plot of the mean target distribution or the statistical tests per chunk.

Select a plot using the kind parameter:

  • distribution

    plots the drift metric per Chunk for the model predictions y_pred.

Parameters:
  • kind (str, default='distribution') – The kind of plot to show. Allowed values are target_drift and target_distribution.

  • plot_reference (bool, default=False) – Indicates whether to include the reference period in the plot or not. Defaults to False.

Returns:

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:

plotly.graph_objs._figure.Figure

Examples

>>> import nannyml as nml
>>>
>>> reference_df, analysis_df, target_df = nml.load_synthetic_binary_classification_dataset()
>>>
>>> calc = nml.TargetDistributionCalculator(
>>>     y_true='work_home_actual',
>>>     timestamp_column_name='timestamp'
>>> )
>>> calc.fit(reference_df)
>>> results = calc.calculate(analysis_df.merge(target_df, on='identifier'))
>>> print(results.data)  # check the numbers
             key  start_index  end_index  ... thresholds  alert significant
0       [0:4999]            0       4999  ...       0.05   True        True
1    [5000:9999]         5000       9999  ...       0.05  False       False
2  [10000:14999]        10000      14999  ...       0.05  False       False
3  [15000:19999]        15000      19999  ...       0.05  False       False
4  [20000:24999]        20000      24999  ...       0.05  False       False
5  [25000:29999]        25000      29999  ...       0.05  False       False
6  [30000:34999]        30000      34999  ...       0.05  False       False
7  [35000:39999]        35000      39999  ...       0.05  False       False
8  [40000:44999]        40000      44999  ...       0.05  False       False
9  [45000:49999]        45000      49999  ...       0.05  False       False
>>>
>>> results.plot(kind='target_drift', plot_reference=True).show()
>>> results.plot(kind='target_distribution', plot_reference=True).show()