stable_cart.plot_prediction_instability¶
- stable_cart.plot_prediction_instability(result, ax=None, max_points=400, random_state=0, band=True, n_bins=25, class_label=None)[source]¶
Draw the instability plot: original prediction against resampled predictions.
One row of the training data is one individual. The x-axis is what the model fitted on the full data predicts for them; the y-axis is what each model fitted on a bootstrap resample predicts for the same individual. A perfectly stable procedure puts every point on the diagonal. The vertical spread at a given x is the honest answer to “how much would this prediction have differed if the data had come out slightly differently”.
Parameters¶
- result
Output of
bootstrap_predictions().- ax
Axes to draw on. A new figure is created when omitted.
- max_points
Cap on the number of individuals scattered — each contributes one dot per resample, so a few hundred is already tens of thousands of dots. Beyond that the cloud saturates into a slab and stops showing density, so a random subset is drawn instead.
- random_state
Seed for that subset.
- band
Overlay the 5th-95th percentile of resampled predictions, binned along the x-axis. This is the part that survives overplotting, and it is what makes the width of the cloud readable rather than merely visible.
- n_bins
Number of equal-count bins for that band.
- class_label
Class whose probability to put on the axes when
resultcontains probability vectors. Required for probability audits. This affects only the display; the audit statistics use the full probability vector.
Returns¶
- Any
The axes, for further customization.
Examples¶
>>> import matplotlib >>> matplotlib.use("Agg") >>> from sklearn.datasets import make_regression >>> from sklearn.tree import DecisionTreeRegressor >>> from stable_cart import bootstrap_predictions, plot_prediction_instability >>> X, y = make_regression(n_samples=200, n_features=5, random_state=0) >>> raw = bootstrap_predictions( ... lambda: DecisionTreeRegressor(max_depth=5, random_state=0), ... X[:150], y[:150], X[150:], n_bootstrap=10, random_state=0, ... ) >>> type(plot_prediction_instability(raw)).__name__ 'Axes'