【问题标题】:Shape Mismatch XGBoost Regressor形状不匹配 XGBoost 回归器
【发布时间】:2022-01-18 14:26:37
【问题描述】:

我已经针对与我打算预测的测试数据具有不同形状的数据训练了 XGBoost Regressor 模型。有没有办法解决这个问题或可以容忍特征不匹配的模型?

在对分类特征进行 One Hot Encoding 时,输入的训练数据和测试数据不匹配。

best_xgb = xgb.XGBRegressor(base_score=0.5, booster='gbtree', colsample_bylevel=1,
             colsample_bynode=1, colsample_bytree=1, enable_categorical=False,
             gamma=0, gpu_id=-1, importance_type=None,
             interaction_constraints='', learning_rate=0.05, max_delta_step=0,
             max_depth=6, min_child_weight=10,monotone_constraints='()', n_estimators=400, n_jobs=4,
             num_parallel_tree=1, predictor='auto', random_state=0, reg_alpha=0,
             reg_lambda=1, scale_pos_weight=1, subsample=1, tree_method='exact',
             validate_parameters=1, verbosity=None)

best_xgb.fit(X, y)

best_xgb.predict(test_data)

我收到以下错误: Shape Mismatch Error

【问题讨论】:

  • 您的test_data 应该与您的火车数据具有相同的形状。也许一些分类特征出现在训练数据中,但没有出现在测试数据中?

标签: python data-science xgboost


【解决方案1】:

请检查 249-235=14 个特征在测试数据中的位置。
或者适合相同的数据
best_xgb.fit(X[test_data.columns], y)

【讨论】:

  • 拟合相同的数据,谢谢@circassia_ai
猜你喜欢
  • 2019-06-10
  • 2019-03-05
  • 2016-05-13
  • 1970-01-01
  • 1970-01-01
  • 2020-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多