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(target_distribution: DataFrame, model_metadata: ModelMetadata)[source]

Bases: object

Contains target distribution data and utilities to plot it.

Creates a new instance of the TargetDistributionResults.

plot(kind: str = 'distribution', distribution: str = 'metric', *args, **kwargs) Figure[source]

Renders a line plot of the target distribution.

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.

Parameters
  • kind (str) – The kind of plot to show. Restricted to the value ‘distribution’.

  • distribution (str, default='metric') – The kind of distribution to plot. Restricted to the values ‘metric’ or ‘statistical’

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)
>>> target_distribution_calc = nml.TargetDistributionCalculator(model_metadata=metadata, chunk_period='W')
>>> target_distribution_calc.fit(ref_df)
>>> target_distribution = target_distribution_calc.calculate(ana_df)
>>> # plot the distribution of the mean
>>> target_distribution.plot(kind='metric').show()
>>> # plot the Chi square statistic
>>> target_distribution.plot(kind='statistical').show()