Skip to main content

models.interaction_screen()

The pairwise interaction screen by permutations (CAS Monograph 16,

Usage

Source

models.interaction_screen(
    model,
    frame,
    y,
    build,
    score,
    features,
    pairs=None,
    splits=None,
    n_repeats=1,
    seed=0,
    n_jobs=None
)

section 9.4): with L_A, L_B and L_AB the losses from shuffling feature A, feature B and both together with the same permutation, L_A + L_B - L_AB is about zero if neither interacts with anything and positive if they interact with each other or with a common third feature. Run it on a flexible model (a boosting model) to find the pairs a GLM might need.

Parameters

model

As for permutation_importance.

frame

As for permutation_importance.

y

As for permutation_importance.

build

As for permutation_importance.

score

As for permutation_importance.

splits

As for permutation_importance.

n_repeats

As for permutation_importance.

seed

As for permutation_importance.

n_jobs

As for permutation_importance.

features: list or dict

As for permutation_importance: names, groups, or labels to names.

pairs: list of (str, str) = None
Pairs of feature labels to screen; every pair by default.

Returns

InteractionScreen

Examples

>>> from prospicio.models import Design, Glm, deviance_score, interaction_screen
>>> a = [float(i % 5) for i in range(40)]
>>> b = [float(i % 3) for i in range(40)]
>>> y = [1.0 + u + v + 2.0 * u * v + (0.1 if i % 2 else -0.1) for i, (u, v) in enumerate(zip(a, b))]
>>> build = lambda f: Design([[1.0] * len(f["a"]), list(f["a"]), list(f["b"]),
...                           [u * v for u, v in zip(f["a"], f["b"])]], ["(Intercept)", "a", "b", "ab"])
>>> fit = Glm("gaussian").fit(build({"a": a, "b": b}), y)
>>> s = interaction_screen(fit, {"a": a, "b": b}, y, build, deviance_score("gaussian"), ["a", "b"])
>>> s.pairs, s.strength[0] > 0

([(‘a’, ‘b’)], True)