Adjusting Plots

NannyML uses Plotly to generate figures and returns plotly.graph_objs._figure.Figure from plot() methods. When you need the plot to do something other than the default plotting, e.g., add another curve or indicate a specific time period in the figure, you can do this by updating the plot.

The example below adds an indicator for a particular period of interest using this method.

>>> import nannyml as nml
>>> reference_df, analysis_df, analysis_targets_df = nml.load_synthetic_car_loan_dataset()

>>> estimator = nml.CBPE(
...     y_pred_proba='y_pred_proba',
...     y_pred='y_pred',
...     y_true='repaid',
...     timestamp_column_name='timestamp',
...     metrics=['roc_auc'],
...     chunk_size=5000,
...     problem_type='classification_binary',
>>> ).fit(reference_df)

>>> estimated_performance = estimator.estimate(analysis_df)
>>> figure = estimated_performance.plot(kind='performance')

>>> # indicate period of interest
>>> import datetime as dt

>>> # add additional indicator for a particular period
>>> figure.add_vrect(
...     x0=dt.datetime(2019,2,28),
...     x1=dt.datetime(2019,4,30),
...     annotation_text="Strategy change",
...     annotation_y=0.8,
...     annotation_position="outside right"
>>> )

>>> figure.show()
../_images/adjusting_plots_time_periods_indication.svg