Plotting binary credal sets on an interval

The plot_credal_set() function also supports 2-class (binary) credal sets. Instead of a ternary simplex the plot renders a horizontal interval on [0, 1] representing P(class 2), with a shaded band showing the credal set and scatter markers at each member distribution.

The same credal set types are supported:

  • Singleton – a single point on the line.

  • Probability intervals – a shaded band between the lower and upper bounds.

  • Distance-based – a shaded band plus a marker at the nominal distribution.

  • Convex / Discrete – a shaded band from the minimum to the maximum member probability, with scatter markers for every vertex.

Each batch element is drawn in a distinct colour.

Singleton credal set

A single probability distribution per instance, shown as a point on the line.

singleton = create_singleton_credal_set(np.array([[0.3, 0.7], [0.6, 0.4]]))
plot_credal_set(singleton, title="Singleton (binary)")
plt.show()
Singleton (binary)

Probability intervals

Per-class lower and upper bounds define a feasible interval on the line.

lower_bounds = np.array([[0.2, 0.4], [0.5, 0.1]])
upper_bounds = np.array([[0.6, 0.8], [0.9, 0.5]])
intervals = create_probability_intervals_from_lower_upper_array(
    np.concatenate([lower_bounds, upper_bounds], axis=-1),
)
plot_credal_set(intervals, title="Probability Intervals (binary)")
plt.show()
Probability Intervals (binary)

Distance-based credal set

A nominal distribution and a radius. The shaded band covers all distributions within total-variation distance; the marker shows the nominal.

distance_based = create_distance_based_credal_set_from_center_and_radius(
    create_categorical_distribution(np.array([[0.4, 0.6], [0.7, 0.3]])),
    np.array([0.15, 0.15]),
)
plot_credal_set(distance_based, title="Distance-Based (binary)")
plt.show()
Distance-Based (binary)

Convex credal set

Explicit vertex distributions. The band spans from the minimum to the maximum P(class 2) across vertices, with markers at each vertex.

# Each vertex is given for both instances.
vertices = [
    create_categorical_distribution(np.array([[0.7, 0.3], [0.4, 0.6]])),
    create_categorical_distribution(np.array([[0.2, 0.8], [0.1, 0.9]])),
    create_categorical_distribution(np.array([[0.5, 0.5], [0.3, 0.7]])),
]
convex = create_convex_credal_set(create_sample(vertices, sample_axis=0))
plot_credal_set(convex, title="Convex (binary)")
plt.show()
Convex (binary)

Discrete credal set

Like the convex case but represents a finite set of distributions rather than their convex hull.

# Each member is given for both instances.
members = [
    create_categorical_distribution(np.array([[0.8, 0.2], [0.6, 0.4]])),
    create_categorical_distribution(np.array([[0.3, 0.7], [0.4, 0.6]])),
]
discrete = create_discrete_credal_set(create_sample(members, sample_axis=0))
plot_credal_set(discrete, title="Discrete (binary)")
plt.show()
Discrete (binary)

Custom labels and configuration

Pass class labels and a PlotConfig to customise the appearance.

config = PlotConfig(fill_alpha=0.5, line_width=2.5, marker_size=60)
plot_credal_set(
    convex,
    title="Custom styling (binary)",
    labels=["Negative", "Positive"],
    config=config,
)
plt.show()
Custom styling (binary)

Total running time of the script: (0 minutes 0.525 seconds)

Gallery generated by Sphinx-Gallery