shap.AdditiveExplainer
- class shap.AdditiveExplainer(model, masker, link=None, feature_names=None, linearize_link=True)
计算广义加性模型的 SHAP 值。
这假设模型只有一阶效应。扩展到二阶和三阶效应是未来的工作(如果您现在将此应用于这些模型,您将得到不正确的、不满足可加性的答案)。
- __init__(model, masker, link=None, feature_names=None, linearize_link=True)
使用给定的掩码器对象为给定模型构建一个 Additive 解释器。
- 参数:
- model函数
一个可调用的 python 对象,它根据一组输入数据样本执行模型。
- masker函数 或 numpy.array 或 pandas.DataFrame
一个可调用的 python 对象,用于“掩盖”隐藏特征,形式为
masker(mask, *fargs)
。它接受一个二进制掩码和一个输入样本,并返回一个掩码样本矩阵。这些掩码样本使用模型函数进行评估,然后对输出进行平均。作为 SHAP 使用的标准掩码的快捷方式,您可以传递一个背景数据矩阵而不是函数,该矩阵将用于掩码。要使用聚类博弈结构,您可以传递一个shap.maskers.Tabular(data, hclustering="correlation")
对象,但请注意,此结构信息对加性模型的解释没有影响。
方法
__init__
(model, masker[, link, ...])使用给定的掩码器对象为给定模型构建一个 Additive 解释器。
explain_row
(*row_args, max_evals, ...])解释单行并返回元组 (row_values, row_expected_values, row_mask_shapes)。
load
(in_file[, model_loader, masker_loader, ...])从给定的文件流加载 Explainer。
save
(out_file[, model_saver, masker_saver])将 explainer 写入给定的文件流。
supports_model_with_masker
(model, masker)确定此 explainer 是否可以处理给定的模型。
- explain_row(*row_args, max_evals, main_effects, error_bounds, batch_size, outputs, silent)
解释单行并返回元组 (row_values, row_expected_values, row_mask_shapes)。
- classmethod load(in_file, model_loader=<bound method Model.load of <class 'shap.models._model.Model'>>, masker_loader=<bound method Serializable.load of <class 'shap.maskers._masker.Masker'>>, instantiate=True)
从给定的文件流加载 Explainer。
- 参数:
- in_file用于从中加载对象的文件流。
- save(out_file, model_saver='.save', masker_saver='.save')
将 explainer 写入给定的文件流。
- static supports_model_with_masker(model, masker)
确定此 explainer 是否可以处理给定的模型。
这是一个抽象静态方法,旨在由每个子类实现。