nannyml.drift.model_inputs.multivariate.data_reconstruction.results module

Implementation of the Data Reconstruction Drift Calculator.

class nannyml.drift.model_inputs.multivariate.data_reconstruction.results.DataReconstructionDriftCalculatorResult(analysis_data: List[nannyml.chunk.Chunk], drift_data: pandas.core.frame.DataFrame, model_metadata: nannyml.metadata.base.ModelMetadata)[source]

Bases: nannyml.drift.base.DriftResult

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

Creates a new DriftResult instance.

Parameters
  • analysis_data (List[Chunk]) – The data that was provided to calculate drift on. This is required in order to plot distributions.

  • drift_data (pd.DataFrame) – The results of the drift calculation.

  • model_metadata (ModelMetadata) – The metadata describing the monitored model. Used to

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

Renders a line plot of the reconstruction_error of the data reconstruction drift calculation results.

Chunks are set on a time-based X-axis by using the period containing their observations. Chunks of different partitions (reference and analysis) are represented using different colors and a vertical separation if the drift results contain multiple partitions.

The different plot kinds that are available:

  • drift: plots drift per Chunk for a chunked data set.

Returns

fig – A Figure object containing the requested drift plot. Can be saved to disk or shown rendered on screen using fig.show().

Return type

plotly.graph_objects.Figure

Examples

>>> import nannyml as nml
>>> ref_df, ana_df, _ = nml.load_synthetic_binary_classification_dataset()
>>> metadata = nml.extract_metadata(ref_df, model_type=nml.ModelType.CLASSIFICATION_BINARY)
>>> drift_calc = nml.DataReconstructionDriftCalculator(model_metadata=metadata, chunk_period='W')
>>> drift_calc.fit(ref_df)
>>> drifts = drift_calc.calculate(ana_df)
>>> # create the data reconstruction drift plot and display it
>>> drifts.plot(kind='drift').show()