lace.engine.Engine.predict

Engine.predict(target: str | int, given: Dict[str | int, object] | None = None, state_ixs: List[int] | None = None, with_uncertainty: bool = True)

Predict a single target from a conditional distribution.

Parameters:
  • target (column index) – The column to predict

  • given (Dict[column index, value], optional) – Column -> Value dictionary describing observations. Note that columns can either be indices (int) or names (str)

  • state_ixs (List[int], optional) – An optional list specifying which states should be used in the prediction. If None (default), use all states.

  • with_uncertainty (bool, optional) – if True (default), return the uncertainty

Returns:

  • pred (value) – The predicted value

  • unc (float, optional) – The uncertainty

Examples

Predict whether an animal swims and return uncertainty

>>> from lace.examples import Animals
>>> animals = Animals()
>>> animals.predict("swims")
(0, 0.008287057807910558)

Predict whether an animal swims given that it has flippers

>>> animals.predict("swims", given={"flippers": 1})
(1, 0.05008037071634858)

Let’s confuse lace and see what happens to its uncertainty. Let’s predict whether an non-water animal with flippers swims

>>> animals.predict("swims", given={"flippers": 1, "water": 0})
(0, 0.32863593091906085)

If you want to save time and you do not care about quantifying your epistemic uncertainty, you don’t have to compute uncertainty.

>>> animals.predict("swims", with_uncertainty=False)
0