nannyml.drift.target.target_distribution.calculator module

Calculates drift for model targets and target distributions using statistical tests.

class nannyml.drift.target.target_distribution.calculator.TargetDistributionCalculator(y_true: str, timestamp_column_name: str, problem_type: Union[str, ProblemType], chunk_size: Optional[int] = None, chunk_number: Optional[int] = None, chunk_period: Optional[str] = None, chunker: Optional[Chunker] = None)[source]

Bases: AbstractCalculator

Calculates drift for model targets and target distributions using statistical tests.

creates a new TargetDistributionCalculator.

Parameters:
  • y_true (str) – The name of the column containing your model target values.

  • timestamp_column_name (str) – The name of the column containing the timestamp of the model prediction.

  • chunk_size (int, default=None) – Splits the data into chunks containing chunks_size observations. Only one of chunk_size, chunk_number or chunk_period should be given.

  • chunk_number (int, default=None) – Splits the data into chunk_number pieces. Only one of chunk_size, chunk_number or chunk_period should be given.

  • chunk_period (str, default=None) – Splits the data according to the given period. Only one of chunk_size, chunk_number or chunk_period should be given.

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

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()