H2O | ExtendedIsolation Forest | model.explain() gives, KeyError: 'response_column'

H2O | ExtendedIsolation Forest | model.explain() gives, KeyError: 'response_column'

几个小时以来,我一直在为这个错误而苦苦挣扎,但即使通读了文档,我还是迷失了方向。

我正在使用 H2O 的扩展隔离林 (EIF)(一种无监督模型)来检测未标记数据集中的异常。这是按预期工作的,但是对于我正在处理模型可解释性的项目来说非常重要。我发现了 explain 函数,据推测它是 returns 模型的几种可解释性方法。我对这个函数的 SHAP 值特别感兴趣。

文档说明

The main functions, h2o.explain() (global explanation) and h2o.explain_row() (local explanation) work for individual H2O models, as well a list of models or an H2O AutoML object. The h2o.explain() function generates a list of explanations.

由于 H2O 模型 link 将我带到一个涵盖监督模型和非监督模型的页面,我假设解释函数适用于两种类型的模型。

尝试 运行 我的代码时,以下代码工作正常。

import h2o
from h2o.estimators import H2OExtendedIsolationForestEstimator

h2o.init()
df_EIF = h2o.H2OFrame(df_EIF)
predictors = df_EIF.columns[0:37]

eif = H2OExtendedIsolationForestEstimator(ntrees = 75, sample_size =500, extension_level = (len(predictors) -1)  )

eif.train(x=predictors, training_frame = df_EIF)
eif_result = eif.predict(df_EIF)
df_EIF['anomaly_score_EIF') = eif_result['anomaly_score']

然而,当尝试调用解释模型时 (eif)

eif.explain(df_EIF)

给我以下 KeyError

KeyError                                  Traceback (most recent call last)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.py in <module>
----> 1 eif.explain(df_EIF)
      2 
      3 
      4 
      5 

C:\ProgramData\Anaconda3\lib\site-packages\h2o\explanation\_explain.py in explain(models, frame, columns, top_n_features, include_explanations, exclude_explanations, plot_overrides, figsize, render, qualitative_colormap, sequential_colormap)
   2895     plt = get_matplotlib_pyplot(False, raise_if_not_available=True)
   2896     (is_aml, models_to_show, classification, multinomial_classification, multiple_models, targets,
-> 2897      tree_models_to_show, models_with_varimp) = _process_models_input(models, frame)
   2898 
   2899     if top_n_features < 0:

C:\ProgramData\Anaconda3\lib\site-packages\h2o\explanation\_explain.py in _process_models_input(models, frame)
   2802         models_with_varimp = [model for model in models if _has_varimp(model)]
   2803     tree_models_to_show = _get_tree_models(models, 1 if is_aml else float("inf"))
-> 2804     y = _get_xy(models_to_show[0])[1]
   2805     classification = frame[y].isfactor()[0]
   2806     multinomial_classification = classification and frame[y].nlevels()[0] > 2

C:\ProgramData\Anaconda3\lib\site-packages\h2o\explanation\_explain.py in _get_xy(model)
   1790     """
   1791     names = model._model_json["output"]["original_names"] or model._model_json["output"]["names"]
-> 1792     y = model.actual_params["response_column"]
   1793     not_x = [
   1794                 y,

KeyError: 'response_column

据我了解,此响应列指的是您要预测的列。但是,由于我处理的是未标记的数据集,因此该响应列不存在。我有办法绕过这个错误吗?甚至可以在无监督模型上使用 explain() 函数吗?如果,那么我该怎么做?如果不可能,是否有另一种方法可以从模型中提取每个变量的 Shap 值?由于 shap.TreeExplainer 似乎也不适用于 H2O 模型。

TL;DR:是否可以在(扩展)隔离林上使用 h2o 中的 .explain() 函数?如果有怎么办?

遗憾的是,H2O-3 中的 explain 方法仅受监督算法支持。

您可以做的是使用替代模型并查看其解释。 基本上,您将在数据上安装 GBM(或 DRF,因为这两个模型支持 TreeSHAP)+ 扩展隔离森林的预测,这将是响应。

这是另一种解释 (E)IF 预测的方法:https://github.com/h2oai/h2o-tutorials/blob/master/tutorials/isolation-forest/interpreting_isolation-forest.ipynb