TaijaPlotting
Documentation for TaijaPlotting.
RecipesBase.apply_recipeRecipesBase.apply_recipeRecipesBase.apply_recipeRecipesBase.apply_recipeRecipesBase.apply_recipeRecipesBase.apply_recipeRecipesBase.apply_recipeTaijaPlotting.animate_pathTaijaPlotting.calibration_plotTaijaPlotting.embed_pathTaijaPlotting.generate_limsTaijaPlotting.get_namesTaijaPlotting.setup_ce_plot
RecipesBase.apply_recipe — Methodplot(
conf_model::ConformalInterval,
fitresult,
X,
y;
input_var=nothing,
zoom=-0.5,
train_lab=nothing,
test_lab=nothing,
)A Plots.jl recipe that can be used to visualize the conformal predictions of a fitted conformal regressor. Data (X,y) are plotted as dots and overlaid with predictions intervals. y is plotted on the vertical axis against a single variable X on the horizontal axis. A shaded area indicates the prediction interval. The line in the center of the interval is the midpoint of the interval and can be interpreted as the point estimate of the conformal regressor. In case X is multi-dimensional, input_var can be used to specify the input variable of interest that will be used for the horizontal axis. If unspecified, the first variable will be plotting by default.
RecipesBase.apply_recipe — Methodplot(
conf_model::ConformalModel,
fitresult,
X
)A Plots.jl recipe that can be used to visualize the set size distribution of a conformal predictor. In the regression case, prediction interval widths are stratified into discrete bins. It can be useful to plot the distribution of set sizes in order to visually asses how adaptive a conformal predictor is. For more adaptive predictors the distribution of set sizes is typically spread out more widely, which reflects that “the procedure is effectively distinguishing between easy and hard inputs”. This is desirable: when for a given sample it is difficult to make predictions, this should be reflected in the set size (or interval width in the regression case). Since ‘difficult’ lies on some spectrum that ranges from ‘very easy’ to ‘very difficult’ the set size should vary across the spectrum of ‘empty set’ to ‘all labels included’.
RecipesBase.apply_recipe — Methodplot(
conf_model::ConformalProbabilisticSet,
fitresult,
X,
y;
input_var=nothing,
target=nothing,
ntest=50,
zoom=-1,
plot_set_size=false,
plot_classification_loss=false,
plot_set_loss=false,
temp=0.1,
κ=0,
loss_matrix=UniformScaling(1.0),
)A Plots.jl recipe that can be used to visualize the conformal predictions of a fitted conformal classifier.
Two Dimensional Inputs
Data (X,y) are plotted as dots and overlaid with predictions sets. y is used to indicate the ground-truth labels of samples by colour. Samples are visualized in a two-dimensional feature space, so it is expected that X $\in \mathcal{R}^2$. By default, a contour is used to visualize the softmax output of the conformal classifier for the target label, where target indicates can be used to define the index of the target label. Transparent regions indicate that the prediction set does not include the target label.
Target
In the binary case, target defaults to 2, indexing the second label: assuming the labels are [0,1] then the softmax output for 1 is shown. In the multi-class cases, target defaults to the first class: for example, if the labels are ["🐶", "🐱", "🐭"] (in that order) then the contour indicates the softmax output for "🐶".
Set Size
If plot_set_size is set to true, then the contour instead visualises the the set size.
Univariate and Higher Dimensional Inputs
In the case of univariate inputs or higher dimensional inputs, a stacked area plot is created: in particular, this method plots the softmax output(s) contained the the conformal predictions set on the vertical axis against an input variable X on the horizontal axis. In the case of multiple input variables, the input_var argument can be used to specify the desired input variable.
RecipesBase.apply_recipe — Methodfunction plot(
M::AbstractFittedModel,
data::CounterfactualData;
target = nothing,
length_out = 100,
zoom = -0.1,
dim_red = :pca,
plot_loss = false,
loss_fun = nothing,
)Calling Plots.plot on a AbstractFittedModel will plot the model's predictions as a contour. The target argument can be used to plot the predictions for a specific target variable. The length_out argument can be used to control the number of points used to plot the contour. The zoom argument can be used to control the zoom of the plot. The dim_red argument can be used to control the method used to reduce the dimensionality of the data if it has more than two features.
RecipesBase.apply_recipe — Methodplot(
ce::CounterfactualExplanation;
target=nothing,
length_out=100,
zoom=-0.1,
dim_red=:pca,
plot_loss=false,
loss_fun=nothing,
plot_up_to = nothing,
n_points = nothing,
)Calling Plots.plot on a CounterfactualExplanation object will plot the training data (scatters), model predictions for the specified target (contour) and the counterfactual path (scatter).
RecipesBase.apply_recipe — Methodplot(data::CounterfactualData; dim_red = :pca)Calling Plots.plot on a data::CounterfactualData object will generate a scatter plot of the data.
RecipesBase.apply_recipe — Methodplot(
la::Laplace,
X::AbstractArray,
y::AbstractArray;
link_approx=:probit,
target=nothing,
length_out=50,
zoom=-1,
)Calling Plots.plot on a Laplace object will plot the posterior predictive distribution and the training data.
TaijaPlotting.animate_path — Functionanimate_path(ce::CounterfactualExplanation, path=tempdir(); plot_proba::Bool=false, kwargs...)Returns and animation of the counterfactual path.
Examples
# Search:
generator = GenericGenerator()
ce = generate_counterfactual(x, target, counterfactual_data, M, generator)
animate_path(ce)TaijaPlotting.calibration_plot — Methodcalibration_plot(y_cal, samp_distr, n_bins)This plot displays the true frequency of points in each confidence interval relative to the predicted fraction of points in that interval. The intervals are taken in step of 0.05 quantiles.
Inputs
la::Laplace– the laplace model to use.Y_cal– a vector of true values y_t.samp_distr– an array of sampled distributions F(xt) corresponding to the yt stacked column-wise.n_bins– numbers of bins to use.
TaijaPlotting.embed_path — Methodembed_path(ce::CounterfactualExplanation)Helper function that embeds path into two dimensions for plotting.
TaijaPlotting.generate_lims — Methodgenerate_lims(x1, x2, xlims, ylims)Small helper function then generates the xlims and ylims for the plot.
TaijaPlotting.get_names — Methodget_names(X)Helper function to get variables names of X.
TaijaPlotting.setup_ce_plot — Methodsetup_ce_plot(ce::CounterfactualExplanation)A helper method that prepares data for plotting.