【问题标题】:eli5 explain_weights_xgboost KeyError: 'bias'eli5 explain_weights_xgboost KeyError: 'bias'
【发布时间】:2020-08-26 06:50:42
【问题描述】:

我是 xgboost 的新手,我训练了一个模型,效果很好。现在我正在尝试使用 eli5 查看权重,我得到: KeyError: 'bias'

-------------------------------------------------- ------------------------- KeyError Traceback(最近一次调用最后一次) 在 3 clf6 = model6.named_steps['clf'] 4 vec6 = model6.named_steps['transformer'] ----> 5 explain_weights_xgboost(clf6, vec=vec6) ~/dev/envs/env3.7/lib/python3.7/site-packages/eli5/xgboost.py 在 explain_weights_xgboost(xgb,vec,top,target_names,targets,feature_names,feature_re,feature_filter,importance_type) 80 描述=DESCRIPTION_XGBOOST, 81 is_regression=is_regression, ---> 82 num_features=coef.shape[-1], 83) 84 ~/dev/envs/env3.7/lib/python3.7/site-packages/eli5/_feature_importances.py in get_feature_importance_explanation(估计器,vec,coef,feature_names,feature_filter,feature_re,top,description,is_regression,estimator_feature_names,num_features, coef_std) 35 特征过滤器=特征过滤器, 36 特征_re=特征_re, ---> 37 num_features=num_features, 38) 39 特征重要性 = 获取特征重要性过滤器( ~/dev/envs/env3.7/lib/python3.7/site-packages/eli5/sklearn/utils.py 在 get_feature_names_filtered(clf,vec,bias_name,feature_names,num_features,feature_filter,feature_re,estimator_feature_names) 第124章 第125章 --> 126 estimator_feature_names=estimator_feature_names, 127) 第128章 ~/dev/envs/env3.7/lib/python3.7/site-packages/eli5/sklearn/utils.py 在 get_feature_names(clf,vec,bias_name,feature_names,num_features,estimator_feature_names) 77 个特征被命名为 x0、x1、x2 等。 78 """ ---> 79 如果没有 has_intercept(clf): 80 偏差名称 = 无 81 ~/dev/envs/env3.7/lib/python3.7/site-packages/eli5/sklearn/utils.py in has_intercept(估计器) 60 if hasattr(estimator, 'fit_intercept'): 61 返回 estimator.fit_intercept ---> 62 if hasattr(estimator, 'intercept_'): 63 如果 estimator.intercept_ 为无: 64返回假 ~/dev/envs/env3.7/lib/python3.7/site-packages/xgboost/sklearn.py in intercept_(self) 第743章 第744章 --> 745 返回 np.array(json.loads(b.get_dump(dump_format='json')[0])['bias']) 746 747 关键错误:“偏见”

谢谢!

【问题讨论】:

    标签: python-3.x xgboost eli5


    【解决方案1】:

    我遇到了同样的问题,并通过在创建估算器时明确指定参数增强器来解决它:

    clf = XGBClassifier(booster='gbtree')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-10
      • 2019-05-15
      • 2017-11-12
      • 2021-08-19
      • 2019-06-21
      • 2018-08-30
      • 2018-12-24
      相关资源
      最近更新 更多