nannyml.performance_estimation.confidence_based.results module

Module containing CBPE estimation results and plotting implementations.

class nannyml.performance_estimation.confidence_based.results.Result(results_data: DataFrame, metrics: List[Metric], y_pred: str, y_pred_proba: Union[str, Dict[str, str]], y_true: str, chunker: Chunker, problem_type: ProblemType, timestamp_column_name: Optional[str] = None)[source]

Bases: PerMetricResult[Metric], ResultCompareMixin

Contains results for CBPE estimation and adds filtering and plotting functionality.

Initialize CBPE results class.

  • results_data (pd.DataFrame) – Results data returned by a CBPE estimator.

  • metrics (List[nannyml.performance_estimation.confidence_based.metrics.Metric]) – List of metrics to evaluate.

  • y_pred (str) – The name of the column containing your model predictions.

  • y_pred_proba (Union[str, Dict[str, str]]) –

    Name(s) of the column(s) containing your model output.
    • For binary classification, pass a single string refering to the model output column.

    • For multiclass classification, pass a dictionary that maps a class string to the column name containing model outputs for that class.

  • y_true (str) – The name of the column containing target values (that are provided in reference data during fitting).

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

  • problem_type (ProblemType) – Determines which CBPE implementation to use. Allowed problem type values are ‘classification_binary’ and ‘classification_multiclass’.

  • timestamp_column_name (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[Key][source]

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

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

Render plots based on CBPE estimation results.

This function will return a plotly.graph_objects.Figure object. The following kinds of plots are available:


kind (str, default='performance') – What kind of plot to create. Only performance type is available.


InvalidArgumentsException – when an unknown plot kind is provided.:


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:



>>> import nannyml as nml
>>> from IPython.display import display
>>> reference_df = nml.load_synthetic_car_loan_dataset()[0]
>>> analysis_df = nml.load_synthetic_car_loan_dataset()[1]
>>> display(reference_df.head(3))
>>> estimator = nml.CBPE(
...     y_pred_proba='y_pred_proba',
...     y_pred='y_pred',
...     y_true='repaid',
...     timestamp_column_name='timestamp',
...     metrics=['roc_auc', 'accuracy', 'f1'],
...     chunk_size=5000,
...     problem_type='classification_binary',
>>> )
>>> results = estimator.estimate(analysis_df)
>>> display(results.filter(period='analysis').to_df())
>>> metric_fig = results.plot()