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

后端 未结 8 1824
悲哀的现实
悲哀的现实 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 13:31

    I came across the same problem and it's been solved by adding passing the train dataframe column name to the test dataframe via adding the following code:

    test_df = test_df[train_df.columns]
    

提交回复
热议问题