compileml.runtime — primitives
contributions_half_micro
from compileml.runtime import contributions_half_micro
Per-feature contributions in half-micro units.
Returns (c2, full, fbase, residual2) where all values are integers, c2[j] is twice the micro-unit contribution of feature j, and residual2 satisfies the spec §7.4 identity exactly.
Computed per tree. A tree that does not split on feature j
contributes nothing to j's main effect, because baselining j
cannot change which leaf the row reaches. The same cancellation is
sharper for pairs: the interaction term
t(x) - t(x_i) - t(x_j) + t(x_ij) vanishes unless the tree splits on
**both** i and j. So each tree only needs its own features
enumerated, and the total is independent of how many features the model
has.
Parameters#
| Name | Type | Default | Kind |
|---|---|---|---|
| model | dict | required | positional |
| x | collections.abc.Sequence[float] | required | positional |
| baseline | collections.abc.Sequence[float] | required | positional |
Returns#
tuple[list[int], int, int, int]