如何使用xgboost.train()

2024-04-26 11:22:14 发布

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

我是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)

Tags: inselfcachetrainparamsitemnumprint