LightGBMでCannot use Dataset instance for prediction, please use raw data instead

LightGBMで2値分類の学習をさせていた際、表題のエラー。

import lightgbm as lgb

lgb_train = lgb.Dataset(X_train, label=y_train)
lgb_eval = lgb.Dataset(X_val, label=y_val)

params = {
        'objective': 'binary',
        'learning_rate': 0.1,
        'verbosity': -1,
        'random_state': SEED
    }

num_round = 10000
model = lgb.train(params,
                  lgb_train,
                  num_round,
                  early_stopping_rounds=100,
                  valid_sets=lgb_eval,
                  )

oof = model.predict(lgb_eval, ntree_limit=model.best_iteration)
File "/opt/conda/lib/python3.7/site-packages/lightgbm/basic.py", line 503, in predict
    raise TypeError("Cannot use Dataset instance for prediction, please use raw data instead")
TypeError: Cannot use Dataset instance for prediction, please use raw data instead

エラーの通り、predictionの時にlgb.Datasetじゃなくて生データを渡してみる。

oof = model.predict(X_val, ntree_limit=model.best_iteration)

これで解決。

コメント

タイトルとURLをコピーしました