【发布时间】: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