ReliabilityModelPlot.ood_hist

static ReliabilityModelPlot.ood_hist(df_rel, figsize=(6, 4.5), bins=20, color='tab:gray', title=None, ax=None)[source]

Histogram of the out-of-distribution score, with the in-domain boundary at 1.0.

Mass to the right of the boundary is out-of-domain — predictions the model is extrapolating and should not be trusted at face value.

Parameters:
  • df_rel (pd.DataFrame) – Output of ReliabilityModel.predict() (needs ood_score).

  • figsize (tuple, default=(6, 4.5)) – Figure size (used only when ax is None).

  • bins (int, default=20) – Number of histogram bins.

  • color (str, default="tab:gray") – Bar color.

  • title (str, optional) – Axes title.

  • ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if None.

Returns:

  • fig (matplotlib.figure.Figure) – The created (or parent) figure.

  • ax (matplotlib.axes.Axes) – The axes drawn on.

Examples

ReliabilityModelPlot().ood_hist() shows the out-of-distribution score distribution from ReliabilityModel.predict(), with the in-domain boundary drawn at 1.0.

import aaanalysis as aa
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
aa.options["verbose"] = False
aa.plot_settings()
X, labels = make_classification(n_samples=160, n_features=10, n_informative=6, random_state=42)
X_train, labels_train = X[:120], labels[:120]
# include one clearly out-of-distribution sample so the trust status is visible
X_new = np.vstack([X[120:], (X_train[labels_train == 1][0] + 20.0)[None, :]])
rm = aa.ReliabilityModel(random_state=42).fit(X=X_train, labels=labels_train)
df_rel = rm.predict(X=X_new)
df_eval = rm.eval(X=X[120:], labels=labels[120:])
aa.ReliabilityModelPlot().ood_hist(df_rel=df_rel, figsize=(6, 4.5), bins=20,
                                   color="tab:gray", title="Applicability domain", ax=None)
plt.tight_layout()
plt.show()
../_images/rm_plot_ood_hist_1_output_2_0.png