viz module
This section contains the Python API reference for the uncertainty_toolbox.viz
module, which contains code for visualizing uncertainties.
uncertainty_toolbox.viz Module
Visualizations for predictive uncertainties and metrics.
- uncertainty_toolbox.viz.filter_subset(input_list, n_subset)
Keep only n_subset random indices from all lists given in input_list.
- Parameters
input_list (
List
[List
[Any
]]) – list of lists.n_subset (
int
) – Number of points to plot after filtering.
- Return type
List
[List
[Any
]]- Returns
List of all input lists with sizes reduced to n_subset.
- uncertainty_toolbox.viz.plot_adversarial_group_calibration(y_pred, y_std, y_true, n_subset=None, cali_type='mean_abs', curve_label=None, group_size=None, score_mean=None, score_stderr=None, ax=None)
Plot adversarial group calibration plots by varying group size from 0% to 100% of dataset size and recording the worst calibration occurred for each group size.
- Parameters
y_pred (
ndarray
) – 1D array of the predicted means for the held out dataset.y_std (
ndarray
) – 1D array of the predicted standard deviations for the held out dataset.y_true (
ndarray
) – 1D array of the true labels in the held out dataset.n_subset (
Optional
[int
]) – Number of points to plot after filtering.cali_type (
str
) – Calibration type str.curve_label (
Optional
[str
]) – legend label str for calibration curve.group_size (
Optional
[ndarray
]) – 1D array of group size ratios in [0, 1].score_mean (
Optional
[ndarray
]) – 1D array of metric means for group size ratios in group_size.score_stderr (
Optional
[ndarray
]) – 1D array of metric standard devations for group size ratios in group_size.ax (
Optional
[Axes
]) – matplotlib.axes.Axes object.
- Return type
Axes
- Returns
matplotlib.axes.Axes object with plot added.
- uncertainty_toolbox.viz.plot_calibration(y_pred, y_std, y_true, n_subset=None, curve_label=None, show=False, vectorized=True, exp_props=None, obs_props=None, ax=None)
Plot the observed proportion vs prediction proportion of outputs falling into a range of intervals, and display miscalibration area.
- Parameters
y_pred (
ndarray
) – 1D array of the predicted means for the held out dataset.y_std (
ndarray
) – 1D array of the predicted standard deviations for the held out dataset.y_true (
ndarray
) – 1D array of the true labels in the held out dataset.n_subset (
Optional
[int
]) – Number of points to plot after filtering.curve_label (
Optional
[str
]) – legend label str for calibration curve.vectorized (
bool
) – plot using get_proportion_lists_vectorized.exp_props (
Optional
[ndarray
]) – plot using the given expected proportions.obs_props (
Optional
[ndarray
]) – plot using the given observed proportions.ax (
Optional
[Axes
]) – matplotlib.axes.Axes object.
- Return type
Axes
- Returns
matplotlib.axes.Axes object with plot added.
- uncertainty_toolbox.viz.plot_intervals(y_pred, y_std, y_true, n_subset=None, ylims=None, num_stds_confidence_bound=2, ax=None)
Plot predictions and predictive intervals versus true values.
- Parameters
y_pred (
ndarray
) – 1D array of the predicted means for the held out dataset.y_std (
ndarray
) – 1D array of the predicted standard deviations for the held out dataset.y_true (
ndarray
) – 1D array of the true labels in the held out dataset.n_subset (
Optional
[int
]) – Number of points to plot after filtering.ylims (
Optional
[Tuple
[float
,float
]]) – a tuple of y axis plotting bounds, given as (lower, upper).num_stds_confidence_bound (
int
) – width of intervals, in terms of number of standard deviations.ax (
Optional
[Axes
]) – matplotlib.axes.Axes object.
- Return type
Axes
- Returns
matplotlib.axes.Axes object with plot added.
- uncertainty_toolbox.viz.plot_intervals_ordered(y_pred, y_std, y_true, n_subset=None, ylims=None, num_stds_confidence_bound=2, ax=None)
Plot predictions and predictive intervals versus true values, with points ordered by true value along x-axis.
- Parameters
y_pred (
ndarray
) – 1D array of the predicted means for the held out dataset.y_std (
ndarray
) – 1D array of the predicted standard deviations for the held out dataset.y_true (
ndarray
) – 1D array of the true labels in the held out dataset.n_subset (
Optional
[int
]) – Number of points to plot after filtering.ylims (
Optional
[Tuple
[float
,float
]]) – a tuple of y axis plotting bounds, given as (lower, upper).num_stds_confidence_bound (
int
) – width of intervals, in terms of number of standard deviations.ax (
Optional
[Axes
]) – matplotlib.axes.Axes object.
- Return type
Axes
- Returns
matplotlib.axes.Axes object with plot added.
- uncertainty_toolbox.viz.plot_residuals_vs_stds(y_pred, y_std, y_true, n_subset=None, ax=None)
Plot absolute value of the prediction residuals versus standard deviations of the predictive uncertainties.
- Parameters
y_pred (
ndarray
) – 1D array of the predicted means for the held out dataset.y_std (
ndarray
) – 1D array of the predicted standard deviations for the held out dataset.y_true (
ndarray
) – 1D array of the true labels in the held out dataset.n_subset (
Optional
[int
]) – Number of points to plot after filtering.ax (
Optional
[Axes
]) – matplotlib.axes.Axes object.
- Return type
Axes
- Returns
matplotlib.axes.Axes object with plot added.
- uncertainty_toolbox.viz.plot_sharpness(y_std, n_subset=None, ax=None)
Plot sharpness of the predictive uncertainties.
- Parameters
y_std (
ndarray
) – 1D array of the predicted standard deviations for the held out dataset.n_subset (
Optional
[int
]) – Number of points to plot after filtering.ax (
Optional
[Axes
]) – matplotlib.axes.Axes object.
- Return type
Axes
- Returns
matplotlib.axes.Axes object with plot added.
- uncertainty_toolbox.viz.plot_xy(y_pred, y_std, y_true, x, n_subset=None, ylims=None, xlims=None, num_stds_confidence_bound=2, leg_loc=3, ax=None)
Plot one-dimensional inputs with associated predicted values, predictive uncertainties, and true values.
- Parameters
y_pred (
ndarray
) – 1D array of the predicted means for the held out dataset.y_std (
ndarray
) – 1D array of the predicted standard deviations for the held out dataset.y_true (
ndarray
) – 1D array of the true labels in the held out dataset.x (
ndarray
) – 1D array of input values for the held out dataset.n_subset (
Optional
[int
]) – Number of points to plot after filtering.ylims (
Optional
[Tuple
[float
,float
]]) – a tuple of y axis plotting bounds, given as (lower, upper).xlims (
Optional
[Tuple
[float
,float
]]) – a tuple of x axis plotting bounds, given as (lower, upper).num_stds_confidence_bound (
int
) – width of confidence band, in terms of number of standard deviations.leg_loc (
Union
[int
,str
]) – location of legend as a str or legend code int.ax (
Optional
[Axes
]) – matplotlib.axes.Axes object.
- Return type
Axes
- Returns
matplotlib.axes.Axes object with plot added.
- uncertainty_toolbox.viz.save_figure(file_name='figure', ext_list=None, white_background=True)
Save matplotlib figure for all extensions in ext_list.
- Parameters
file_name (
str
) – name of saved image file.ext_list (
Union
[list
,str
,None
]) – list of strings (or single string) denoting file type.white_background (
bool
) – set background of image to white if True.
- Return type
NoReturn
- uncertainty_toolbox.viz.set_style(style_str='default')
Set the matplotlib plotting style.
- Parameters
style_str (
str
) – string for style file.- Return type
NoReturn
- uncertainty_toolbox.viz.update_rc(key_str, value)
Update matplotlibrc parameters.
- Parameters
key_str (
str
) – string for a matplotlibrc parameter.value (
Any
) – associated value to set the matplotlibrc parameter.
- Return type
NoReturn