foxplainer package

Submodules

foxplainer.data module

class foxplainer.data.Data(filename=None, fpointer=None, mapfile=None, separator=' ', use_categorical=False)

Bases: object

Class for representing data (transactions).

parse(fp, separator)

Parse input file.

foxplainer.explainer module

class foxplainer.explainer.FoX(global_model_name=None, xtype='abd', xnum=1, global_model_path=None, proj_name=None, data_path=None, inst_id=0)

Bases: object

A FoX object should be initialized with the following attributes to perform the logical explanation

Parameters:
  • global_model_name (str) – The black-box global model to be explained, currently support 2 models, ‘LR’ for Logistic Regression and ‘RF’ for Random Forest

  • xtype (str optional) – Explanation type, currently support 2 types, ‘abd’ for Abductive Explanation and ‘con’ for Concretive Explanation

  • xnum (int or str) – Number of explanations to be generated for each instance, this should be either 1 or “all”

  • global_model_path (str) – Path to the global model file in .pkl format trained by the sklearn library

  • proj_name (str) – Project name

  • data_path (str) – Path to the data files required for the FoX

  • inst_id (int) – The row index of the instance to be explained

exp_mapping(if_else_text)
exp_to_html(exp_list=None, exp_type=None, explained_instance=None)
explain(in_jupyter=False)

Main function to perform the logical explanation

ffa(explanation_list)

unweighted feature attribution

save_ffa_graph(f2imprt)
show_in_jupyter(show_both_exp=False) None

foxplainer.lrxp module

class foxplainer.lrxp.LRExplainer(data, options)

Bases: object

enumrate(inst)
equal_pred(lbounds, ubounds)
explain(inst)
extract_AXp(inst, seed={})
extract_CXp(inst, seed={})
extract_bound(i)
extract_bounds()
fix_attr(i, inst, lbounds, ubounds, deset, inset)
free_attr(i, inst, lbounds, ubounds, deset, inset)

foxplainer.options module

class foxplainer.options.Options(global_model_name, xtype, xnum, global_model_path, proj_name, data_path)

Bases: object

Class for representing command-line options.

foxplainer.rndmforest module

class foxplainer.rndmforest.Dataset(filename=None, fpointer=None, mapfile=None, separator=',', use_categorical=False)

Bases: Data

Class for representing dataset (transactions).

mapping_features()
readable_sample(x)
transform(x)
class foxplainer.rndmforest.RF2001(options)

Bases: object

The main class to train Random Forest Classifier (RFC).

estimators()
class foxplainer.rndmforest.SATEncoder(forest, feats, nof_classes, extended_feature_names, from_file=None)

Bases: object

Encoder of Random Forest classifier into SAT.

compute_intervals()

Traverse all trees in the ensemble and extract intervals for each feature.

At this point, the method only works for numerical datasets!

encode(sample)

Do the job.

maj_vote_const(ctvars)

capture majority class vote with cardinality constraints (Pseudo Boolean..)

newVar(name)
traverse(tree, k, clause)

Traverse a tree and encode each node.

class foxplainer.rndmforest.SATExplainer(sat_enc, inps, preamble, label, target_name, options, verb=1)

Bases: object

An SAT-inspired minimal explanation extractor for Random Forest models.

explain(sample)

Hypotheses minimization.

extract_mus(start_from=None)

Compute any subset-minimal explanation.

mhs_mus_enumeration()

Enumerate subset- and cardinality-minimal explanations.

prepare(sample)

Prepare the oracle for computing an explanation.

class foxplainer.rndmforest.XRF(dataset, options)

Bases: object

class to encode and explain Random Forest classifiers.

encode(inst)

Encode a tree ensemble trained previously.

explain(inst)

Explain a prediction made for a given sample with a previously trained RF.

foxplainer.rndmforest.pickle_load_file(filename)

foxplainer.tree module

class foxplainer.tree.Forest(rf, feature_names=None)

Bases: object

An ensemble of decision trees.

This object provides a common interface to many different types of models.

predict_inst(inst)
foxplainer.tree.build_tree(tree_, feature_names=None)
foxplainer.tree.count_nodes(root)
class foxplainer.tree.dt_node(id, parent=None)

Bases: Node

foxplainer.tree.predict_tree(node, sample)

Module contents