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.

Uncertainty is the normalized mean total variation distance between each state’s predictive distribution and the average predictive distribution.

  • 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


  • pred (value) – The predicted value

  • unc (float, optional) – The uncertainty


Predict whether an animal swims and return uncertainty

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

Predict whether an animal swims given that it has flippers

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

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.36077426258767503)

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)