from relax.data import load_data
from relax.module import PredictiveTrainingModule, PredictiveTrainingModuleConfigs, load_pred_model
from relax.evaluate import generate_cf_explanations, benchmark_cfs
from relax.trainer import train_model
Diverse CF
DIVERSECFCONFIG
CLASS relax.methods.diverse.DiverseCFConfig (n_cfs=5, n_steps=1000, lr=0.01, lambda_=0.01, seed=42)
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
DIVERSECF
CLASS relax.methods.diverse.DiverseCF (configs=None)
Base CF Explanation Module.
Load data:
= load_data('adult', data_configs=dict(sample_frac=0.1)) dm
/home/birk/miniconda3/envs/nbdev2/lib/python3.8/site-packages/sklearn/preprocessing/_encoders.py:868: FutureWarning: `sparse` was renamed to `sparse_output` in version 1.2 and will be removed in 1.4. `sparse_output` is ignored unless you leave `sparse` to its default value.
warnings.warn(
Train predictive model:
# load model
= load_pred_model('adult')
params, training_module
# predict function
= training_module.pred_fn pred_fn
Define DiverseCF
:
= DiverseCF() diversecf
Generate explanations:
= generate_cf_explanations(
cf_exp =pred_fn,
diversecf, dm, pred_fn=dict(
pred_fn_args=params, rng_key=random.PRNGKey(0)
params
) )
Evaluate explanations:
benchmark_cfs([cf_exp])
acc | validity | proximity | ||
---|---|---|---|---|
adult | DiverseCF | 0.8241 | 0.393932 | 1.913267 |