【问题标题】:How to use xgboost.train()如何使用 xgboost.train()
【发布时间】:2021-04-10 16:14:40
【问题描述】:

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

【问题讨论】:

    标签: python jupyter-notebook google-colaboratory xgboost valueerror


    【解决方案1】:

    XGB 要求您将数据帧转换为 DMatrix 以供其处理

            d_train = xgb.DMatrix(X_train, label=y_train)
            d_test = xgb.DMatrix(X_test, label=y_test)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      • 2012-02-29
      相关资源
      最近更新 更多