shap.maskers.Partition

class shap.maskers.Partition(data, max_samples=100, clustering='correlation')

通过对给定背景数据集进行积分来掩盖表格特征。

与 Independent 不同,Partition 尊重数据的分层结构。

__init__(data, max_samples=100, clustering='correlation')

使用给定的背景数据和聚类构建 Partition masker。

参数:
datanumpy.ndarray, pandas.DataFrame

用于掩码的背景数据集。

max_samplesint

从传入的背景数据中使用的最大样本数。如果数据超过 max_samples,则使用 shap.utils.sample 对数据集进行二次抽样。从 masker 中出来的样本数(用于积分)与背景数据集中的样本数匹配。这意味着更大的背景数据集会导致更长的运行时间。通常,大约 1、10、100 或 1000 个背景样本是合理的选择。

clusteringstring 或 numpy.ndarray

如果是一个字符串,则这是用于创建特征聚类的距离度量。距离函数可以是任何有效的 scipy.spatial.distance.pdist 的度量参数。但是,我们建议在大多数情况下使用“correlation”。完整的选项列表是 braycurtiscanberrachebyshevcityblockcorrelationcosinediceeuclideanhammingjaccardjensenshannonkulsinskimahalanobismatchingminkowskirogerstanimotorussellraoseuclideansokalmichenersokalsneathsqeuclideanyule。这些都是 scipy.spatial.distance.pdist 的度量参数中的所有选项。如果是一个数组,则假定这是特征的聚类。

方法

__init__(data[, max_samples, clustering])

使用给定的背景数据和聚类构建 Partition masker。

invariants(x)

这返回一个蒙版,指示当我们遮盖特征时哪些特征会发生变化。

load(in_file[, instantiate])

从文件流中加载 Tabular masker。

save(out_file)

将 Tabular masker 写入文件流。

属性

shape

clustering

invariants(x)

这返回一个蒙版,指示当我们遮盖特征时哪些特征会发生变化。

这种可选的遮盖方法允许解释器避免在被遮盖的特征都是不变时重新评估模型。

classmethod load(in_file, instantiate=True)

从文件流中加载 Tabular masker。

save(out_file)

将 Tabular masker 写入文件流。