我正在尝试在熊猫数据框上运行预测方法。
我训练了模型,并加载了新数据以进行预测。
我的模型的类型为: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()```