eli5预测方法的误差

2024-07-05 12:38:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在熊猫数据帧上运行预测方法。你知道吗

我对模型进行了训练,并加载了新的数据进行预测。你知道吗

我的模型的类型是:xgboost.core.Booster

我的声明如下:

expl = eli5.explain_prediction_xgboost(model, features_pred.iloc[0,:])

我试着将pandas df作为numpy数组加载,并且试着恢复到eli5的早期版本,但是似乎没有什么能解决这个问题。你知道吗

我得到这个错误的数据帧是147列宽和400k+行长,所以很难在这样一个狭小的空间里“重现”这个问题。但是,简而言之,要复制,您需要创建xgboost模型,在数据帧上对其进行训练,然后运行以下命令来尝试解释第一行的预测:

expl = eli5.explain_prediction_xgboost(model, features_pred.iloc[0,:])

我收到的错误消息如下:


TypeError: object of type 'numpy.int32' has no len()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<command-197845> in <module>
      4 # for i in range(len(features_pred)):
      5 
----> 6 expl = eli5.explain_prediction_xgboost(model, features_pred.iloc[2,:])
      7 
      8 #expl = eli5.explain_prediction_xgboost(booster, features_pred.iloc[0])

/databricks/python/lib/python3.5/site-packages/eli5/xgboost.py in explain_prediction_xgboost(xgb, doc, vec, top, top_targets, target_names, targets, feature_names, feature_re, feature_filter, vectorized, is_regression, missing)
    194 
    195     scores_weights = _prediction_feature_weights(
--> 196         booster, dmatrix, n_targets, feature_names, xgb_feature_names)
    197 
    198     x = get_X0(add_intercept(X))

/databricks/python/lib/python3.5/site-packages/eli5/xgboost.py in _prediction_feature_weights(booster, dmatrix, n_targets, feature_names, xgb_feature_names)
    244     xgb_feature_names = {f: i for i, f in enumerate(xgb_feature_names)}
    245     tree_dumps = booster.get_dump(with_stats=True)
--> 246     assert len(tree_dumps) == len(leaf_ids)
    247 
    248     target_feature_weights = partial(

TypeError: object of type 'numpy.int32' has no len()```

Tags: 数据inlennamesfeaturefeaturespredictionbooster