我已经为这个错误挣扎了几个小时,但是在阅读了文档之后,我似乎已经迷失了方向。
我正在使用H2O的扩展隔离森林(EIF),一个无监督的模型,来检测一个无标签数据集中的异常。但是,对于我正在进行的项目来说,模型的可解释性是非常重要的。我发现了解释函数,它应该返回模型的几个可解释的方法。我对这个函数的SHAP值特别感兴趣。
文件说明
主要函数h2o.explain() (全局解释)和h2o.explain_row() (本地解释)适用于单个H2O模型,以及模型列表或H2O AutoML对象。h2o.explain()函数生成一个解释列表。
由于H2O模型链接将我带到一个页面,该页面涵盖了有监督的和非监督的模型,因此我假设解释函数将适用于这两种类型的模型。
当试图运行我的代码时,下面的代码工作得很好。
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的h2o()函数吗?如果是的话,怎么做?
发布于 2022-05-03 12:22:55
不幸的是,H2O-3中的explain方法只支持有监督的算法.
你能做的就是使用一个代孕模型,并看一看关于它的解释。基本上,您可以在数据+扩展隔离林的预测(这将是响应)上安装一个GBM (或者DRF,因为这两个模型支持TreeSHAP)。
发布于 2022-05-03 19:50:29
以下是解释(E)IF:isolation-forest.ipynb预测的另一种方法
https://stackoverflow.com/questions/72098968
复制相似问题