如何解决如何使用 xgboost.train()
我是 XGBoost 的新手,我想使用 train() 函数,但是当我尝试使用时,出现以下错误
146 else:
147 try:
148 main()
149 except KeyboardInterrupt:
150 print("KeyboardInterrupt,exiting")
/usr/local/lib/python3.6/dist-packages/xgboost/core.py in __init__(self,params,cache,model_file)
938 for d in cache:
939 if not isinstance(d,DMatrix):
940 raise TypeError('invalid cache item: {}'.format(type(d).__name__))
941 self._validate_features(d)
942
TypeError: invalid cache item: DataFrame
我的代码是
import xgboost as xgb
xgb_params = {
"objective": "multi:softmax","eta": 0.3,"num_class": 62,"max_depth": 10,"nthread": 4,"eval_metric": "merror","print.every.n": 1
#"silent": 1
}
clf = xgb.train(params=xgb_params,dtrain=df,num_boost_round=10)
解决方法
XGB 要求您将数据帧转换为 DMatrix 以供处理
d_train = xgb.DMatrix(X_train,label=y_train)
d_test = xgb.DMatrix(X_test,label=y_test)