Prediction Sets¶
The unified conformal prediction-set hierarchy. Every conformal regressor and
classifier in online-cp returns one of these objects (or a
MultiLevelPredictionSet when epsilon is an array-like).
The hierarchy:
ConformalPredictionSet (abstract)
├── EmptyPredictionSet # ∅
├── DiscretePredictionSet # {0, 1, 2} — classifiers
└── ContinuousPredictionSet # 1 to N closed intervals [a, b]
ConformalPredictionSet— abstract base with the shared interfaceEmptyPredictionSet— the empty set ∅DiscretePredictionSet— classifier label setsContinuousPredictionSet— one or more disjoint closed intervals[a, b]MultiLevelPredictionSet— prediction sets at multiple significance levels
online_cp.prediction_set.ConformalPredictionSet
¶
Bases: ABC
Abstract base for all conformal prediction sets.
A concrete prediction set is one of EmptyPredictionSet,
DiscretePredictionSet or ContinuousPredictionSet. Instances of
the base class are not meant to be created directly — use a subclass.
Source code in src/online_cp/prediction_set.py
is_empty: bool
property
¶
True if the prediction set contains no values.
For the base class the default is True — a bare
ConformalPredictionSet() represents the empty set. Subclasses
override with the correct semantics.
is_discrete: bool
abstractmethod
property
¶
True if the set contains discrete elements (classifiers).
is_continuous: bool
abstractmethod
property
¶
True if the set contains continuous intervals (regressors).
__contains__(y: Any) -> bool
abstractmethod
¶
width() -> float
abstractmethod
¶
Total width of the prediction set.
Returns 0.0 for empty sets, np.inf for unbounded continuous
sets, the number of elements for discrete sets, and the sum of
interval lengths for bounded continuous sets.
Source code in src/online_cp/prediction_set.py
online_cp.prediction_set.EmptyPredictionSet
¶
Bases: ConformalPredictionSet
The empty prediction set ∅.
Returned when no y satisfies the conformal condition p(y) > ε
(i.e. the super-level set is empty).
Source code in src/online_cp/prediction_set.py
online_cp.prediction_set.DiscretePredictionSet
¶
Bases: ConformalPredictionSet
A discrete prediction set (classifiers).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
array - like
|
The set of labels contained in the prediction set. |
required |
epsilon
|
float
|
Significance level at which the set was constructed. |
required |
Examples:
>>> s = DiscretePredictionSet(np.array([0, 1, 2]), epsilon=0.1)
>>> s.is_discrete
True
>>> s.width()
3.0
>>> 1 in s
True
>>> 3 in s
False
Source code in src/online_cp/prediction_set.py
online_cp.prediction_set.ContinuousPredictionSet
¶
Bases: ConformalPredictionSet
A continuous prediction set: one or more disjoint closed intervals.
All intervals are closed [a, b]. The endpoints are numeric
real bounds; the special value np.inf is allowed for rays. A
degenerate [a, a] interval represents the single point {a}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intervals
|
list[tuple[float, float]]
|
One or more closed intervals |
required |
epsilon
|
float
|
Significance level at which the set was constructed. |
required |
Examples:
>>> s = ContinuousPredictionSet([(1.2, 3.7)], epsilon=0.1)
>>> s.is_continuous
True
>>> s.is_single_interval
True
>>> s.width()
2.5
>>> 1.2 in s # boundary included (closed)
True
>>> 3.7 in s # boundary included (closed)
True
>>> 2.0 in s
True
Source code in src/online_cp/prediction_set.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
intervals: list[tuple[float, float]]
property
¶
Return the list of closed intervals in canonical form.
is_single_interval: bool
property
¶
True if the set is a single connected component.
lower: float
property
¶
Lower bound of the first interval.
.. deprecated::
Prefer .intervals[0][0]. Retained for backward compatibility
with the old ConformalPredictionInterval class.
upper: float
property
¶
Upper bound of the last interval.
.. deprecated::
Prefer .intervals[-1][1]. Retained for backward compatibility
with the old ConformalPredictionInterval class.
to_single_interval() -> tuple[float, float] | None
¶
Return (lower, upper) if single interval, else None.
online_cp.prediction_set.MultiLevelPredictionSet
¶
Prediction sets at multiple significance levels (unified).
Returned by predict (and predict_set) when epsilon is an
array-like. Replaces the legacy MultiLevelPredictionInterval
(regressors) and MultiLevelPredictionSet (classifiers) with a single
class that works for both discrete and continuous prediction sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
dict[float, ConformalPredictionSet]
|
Mapping |
required |
Examples:
>>> from online_cp.prediction_set import DiscretePredictionSet
>>> ml = MultiLevelPredictionSet({
... 0.1: DiscretePredictionSet(np.array([0, 1]), 0.1),
... 0.2: DiscretePredictionSet(np.array([0, 1, 2]), 0.2),
... })
>>> ml.levels
[0.1, 0.2]
>>> 0 in ml
True
>>> 2 in ml[0.2]
True
Source code in src/online_cp/prediction_set.py
Interval notation¶
All numeric bounds are closed [a, b] — the inclusion criterion is the
super-level set {y : p(y) > ε}, which for a continuous nonconformity measure
is algebraically {y : α(y) ≤ c}, a closed set. Infinity bounds stay
parenthesised because ∞ is not a real number.
| Type | Notation | Python representation |
|---|---|---|
| Single / Disjoint | [a, b] |
ContinuousPredictionSet([(a, b)], epsilon) |
| Ray (bounded below) | [a, ∞) |
ContinuousPredictionSet([(a, np.inf)], epsilon) |
| Ray (bounded above) | (-∞, b] |
ContinuousPredictionSet([(-np.inf, b)], epsilon) |
| All reals | (-∞, ∞) |
ContinuousPredictionSet([(-np.inf, np.inf)], epsilon) |
| Single point | [a, a] |
ContinuousPredictionSet([(a, a)], epsilon) |
| Empty | ∅ |
EmptyPredictionSet() |