alibi.explainers.anchors.anchor_tabular_distributed module

class alibi.explainers.anchors.anchor_tabular_distributed.DistributedAnchorBaseBeam(samplers, **kwargs)[source]

Bases: AnchorBaseBeam

draw_samples(anchors, batch_size)[source]

Distributes sampling requests among processes running sampling tasks.

Parameters:
Return type:

Tuple[ndarray, ndarray]

Returns:

See alibi.explainers.anchors.anchor_base.AnchorBaseBeam.draw_samples() implementation.

class alibi.explainers.anchors.anchor_tabular_distributed.DistributedAnchorTabular(predictor, feature_names, categorical_names=None, dtype=<class 'numpy.float32'>, ohe=False, seed=None)[source]

Bases: AnchorTabular

explain(X, threshold=0.95, delta=0.1, tau=0.15, batch_size=100, coverage_samples=10000, beam_size=1, stop_on_first=False, max_anchor_size=None, min_samples_start=1, n_covered_ex=10, binary_cache_size=10000, cache_margin=1000, verbose=False, verbose_every=1, **kwargs)[source]

Explains the prediction made by a classifier on instance X. Sampling is done in parallel over a number of cores specified in kwargs[‘ncpu’].

Parameters:
Return type:

Explanation

Returns:

See alibi.explainers.anchors.anchor_tabular.AnchorTabular.explain() superclass.

fit(train_data, disc_perc=(25, 50, 75), **kwargs)[source]

Creates a list of handles to parallel processes handles that are used for submitting sampling tasks.

Parameters:
Return type:

AnchorTabular

reset_predictor(predictor)[source]

Resets the predictor function.

Parameters:

predictor (Callable) – New model prediction function.

Return type:

None

class alibi.explainers.anchors.anchor_tabular_distributed.RemoteSampler(*args)[source]

Bases: object

A wrapper that facilitates the use of TabularSampler for distributed sampling.

__call__(anchors_batch, num_samples, compute_labels=True)[source]

Wrapper around alibi.explainers.anchors.anchor_tabular.TabularSampler.__call__(). It allows sampling a batch of anchors in the same process, which can improve performance.

Parameters:
Return type:

List

build_lookups(X)[source]

Wrapper around alibi.explainers.anchors.anchor_tabular.TabularSampler.build_lookups().

Parameters:

X (ndarray) – See alibi.explainers.anchors.anchor_tabular.TabularSampler.build_lookups().

Returns:

See alibi.explainers.anchors.anchor_tabular.TabularSampler.build_lookups().

set_instance_label(X)[source]

Sets the remote sampler instance label.

Parameters:

X (ndarray) – The instance to be explained.

Return type:

int

Returns:

label – The label of the instance to be explained.

set_n_covered(n_covered)[source]

Sets the remote sampler number of examples to save for inspection.

Parameters:

n_covered (int) – Number of examples where the result (and partial anchors) apply.

Return type:

None