ValueError: feature_names mismatch: in xgboost in the predict() function

后端 未结 8 1845
悲哀的现实
悲哀的现实 2020-12-25 13:15

I have trained an XGBoostRegressor model. When I have to use this trained model for predicting for a new input, the predict() function throws a feature_names mismatch error,

8条回答
  •  误落风尘
    2020-12-25 13:39

    Try converting data into ndarray before passing it to fit/predict. For eg: if your train data is train_df and test data is test_df. Use below code:

    train_x = train_df.values
    test_x = test_df.values
    

    Now fit the model:

    xgb.fit(train_x,train_y)
    

    Finally, predict:

    pred = xgb.predict(test_x)
    

    Hope this helps!

提交回复
热议问题