shapiq_benchmark.setups.InterventionalTreeSetup

class shapiq_benchmark.setups.InterventionalTreeSetup(*, dataset, random_state=42, dataset_params=<factory>, test_size=0.2, model='decision_tree', preset=None, model_params=<factory>, x=0, n_reference=100, class_index=None, normalize=False)[source]

Bases: ModelSetup

An InterventionalTreeGame of a tree model trained on a dataset.

The reference data is a seeded random subset of the training split; the explained point is taken from the test split.

Variables:
  • model – A tree model name (see PathDependentTreeSetup). Defaults to "decision_tree".

  • x – The index of the explained point in the test split. Defaults to 0.

  • n_reference – The number of reference rows. Defaults to 100.

  • class_index – The explained class for classifiers (None means class 1).

  • normalize – Whether to center the game. Defaults to False.

Examples

>>> setup = InterventionalTreeSetup(dataset="xor", n_reference=20)
>>> setup.build().reference_data.shape
(20, 4)
build()[source]

Train the model and build the game.

Return type:

InterventionalTreeGame

estimator(task, **overrides)

Return the unfitted, seeded model for a task.

Parameters:
  • task (Task) – "classification" or "regression".

  • **overrides (Any) – Hyperparameters overriding model_params.

Return type:

Any

fit(split)

Return the seeded model fitted on the training part of split.

Return type:

Any

load()

Load the dataset.

Return type:

Dataset

load_split()

Load the dataset and split it (seeded, stratified for classification).

Return type:

DatasetSplit

sample_rows(n_rows, n)

Return n sorted row indices out of n_rows, drawn with random_state.

All rows are returned if n is None or at least n_rows.

Return type:

ndarray

stratified_rows(y, n, task)

Return n sorted row indices, drawn with random_state and stratified by class.

The rows are stratified for classification where every class has enough rows. All rows are returned if n is None or at least the number of rows.

Return type:

GenericAlias[integer]

to_dict()

Return the setup as a JSON-serializable dictionary (the inverse of setup_from_dict()).

Return type:

dict[str, Any]

class_index = None
dataset
dataset_params
property key

A stable identifier of the game this setup builds, used as its cache key.

It is a digest of the setup’s name, version, RECIPE_VERSION, and fields (runtime fields excluded), so it is the same across processes and machines.

model = 'decision_tree'
model_params
n_reference = 100
name = 'interventional_tree'

The registered name of the setup.

normalize = False
preset = None
random_state = 42
tasks = ('classification', 'regression')

The tasks of the datasets the setup accepts.

test_size = 0.2
version = 1

The version of build(), part of key.

x = 0