在使用 LIME 进行模型解释时处理类别、浮点数和整型特征

Handling category, float and int type features while using LIME for model interpretation

我正在使用具有混合特征类型的 Lime(本地可解释模型不可知解释)来评估我对分类任务的模型预测。有谁知道如何在 lime.lime_tabular.LimeTabularExplainer() 方法中指定二进制特征。 LIME 实际上如何处理这些类型的特征(更多特征只有 1 和 0)?

我认为您应该将二元特征声明为分类特征,以便您的 Lime 解释器在对研究样本进行局部扰动时有效地使用其采样机制。

您可以使用 categorical_features 中的关键字参数 LimeTabularExplainer 构造函数.

my_binary_feature_column_index = 0 # put your column index here    

explainer = LimeTabularExplainer(my_data, categorical_features=[my_binary_feature_column_index], categorical_name={my_binary_feature_column_index: ["foo", "bar", "baz"]})
  • categorical_features是分类列索引的列表,
  • categorical_name 是一个包含列索引映射和类别名称列表的字典。

正如 LIME 代码中提到的那样:

Explains predictions on tabular (i.e. matrix) data. For numerical features, perturb them by sampling from a Normal(0,1) and doing the inverse operation of mean-centering and scaling, according to the means and stds in the training data. For categorical features, perturb by sampling according to the training distribution, and making a binary feature that is 1 when the value is the same as the instance being explained.

因此,分类特征是一种热编码,根据训练数据集中的特征分布使用值 0 或 1(除非您选择使用 LabelEncoder,这将导致 LIME 处理特征作为连续变量)。

LIME 项目中提供了一个很好的教程:https://github.com/marcotcr/lime/blob/master/doc/notebooks/Tutorial%20-%20continuous%20and%20categorical%20features.ipynb