Skip to main content

models.ice()

Individual conditional expectation curves (Goldstein, Kapelner, Bleich

Usage

Source

models.ice(
    model,
    frame,
    build,
    feature,
    values,
)

and Pitkin, 2015): each row’s prediction with feature set to each value and its other columns as they are. Their mean is partial_dependence; curves that cross or fan out show an interaction the mean hides.

Parameters

model: object

A fitted model with predict(design).

frame: dict

Column name to values, the rows to explain.

build: callable

build(frame) -> Design.

feature: str

One column of frame.

values: list
The values to set it to.

Returns

IceCurves

Examples

>>> from prospicio.models import Design, Glm, ice, partial_dependence
>>> f = {"x": [float(i % 4) for i in range(40)], "z": [float(i % 3) for i in range(40)]}
>>> build = lambda f: Design([[1.0] * len(f["x"]), list(f["x"]), list(f["z"])], ["(Intercept)", "x", "z"])
>>> fit = Glm("poisson").fit(build(f), [1.0 + (i % 5) for i in range(40)])
>>> curves = ice(fit, f, build, "x", [0.0, 3.0])
>>> pd = partial_dependence(fit, f, build, "x", [0.0, 3.0])
>>> [round(a - b, 12) for a, b in zip(curves.mean, pd.mean)]

[0.0, 0.0]