nannyml.drift.multivariate.data_reconstruction.result module

Contains the results of the data reconstruction drift calculation and provides plotting functionality.

class nannyml.drift.multivariate.data_reconstruction.result.Metric(display_name, column_name)

Bases: tuple

Create new instance of Metric(display_name, column_name)

column_name

Alias for field number 1

display_name

Alias for field number 0

class nannyml.drift.multivariate.data_reconstruction.result.Result(results_data: pandas.core.frame.DataFrame, column_names: List[str], categorical_column_names: List[str], continuous_column_names: List[str], timestamp_column_name: Optional[str] = None)[source]

Bases: nannyml.base.PerMetricResult[nannyml.drift.multivariate.data_reconstruction.result.Metric], nannyml.plots.blueprints.comparisons.ResultCompareMixin

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

Parameters
  • 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.

  • 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.

keys() List[nannyml._typing.Key][source]

Creates a list of keys where each Key is a namedtuple(‘Key’, ‘properties display_names’)

plot(kind: str = 'drift', *args, **kwargs) plotly.graph_objs._figure.Figure[source]

Renders plots for metrics returned by the multivariate data reconstruction calculator.

Parameters

kind (str, default='drift') – The kind of plot you want to have. Value can currently only be ‘drift’.

Raises

InvalidArgumentsException – when an unknown plot kind is provided.:

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, _ = nml.load_synthetic_binary_classification_dataset()
>>>
>>> column_names = [col for col in reference_df.columns
>>>                 if col not in ['y_pred', 'y_pred_proba', 'work_home_actual', 'timestamp']]
>>> calc = nml.DataReconstructionDriftCalculator(
>>>     column_names=column_names,
>>>     timestamp_column_name='timestamp'
>>> )
>>> calc.fit(reference_df)
>>> results = calc.calculate(analysis_df)
>>> print(results.to_df())  # access the data as a pd.DataFrame
                     key  start_index  ...  upper_threshold alert
0       [0:4999]            0  ...         1.511762  True
1    [5000:9999]         5000  ...         1.511762  True
2  [10000:14999]        10000  ...         1.511762  True
3  [15000:19999]        15000  ...         1.511762  True
4  [20000:24999]        20000  ...         1.511762  True
5  [25000:29999]        25000  ...         1.511762  True
6  [30000:34999]        30000  ...         1.511762  True
7  [35000:39999]        35000  ...         1.511762  True
8  [40000:44999]        40000  ...         1.511762  True
9  [45000:49999]        45000  ...         1.511762  True
>>> fig = results.plot(plot_reference=True)
>>> fig.show()