该函数在预测时失败并出现错误:
f"Feature shape mismatch, expected: {self.num_features()}, "
ValueError: Feature shape mismatch, expected: 395, got 395
testX - 1 X 395(数据帧) trainX - n X 395(数据帧)
def xgboost_forecast(train, testX):
# split into input and output columns
testX = np.asarray(testX)
testX = testX.reshape(-1, 1)
trainX, trainy = train.iloc[:, :-1], train.iloc[:, -1]
trainy = np.asarray(trainy)
trainy = trainy.reshape(-1, 1)
# fit model
model = xgb.XGBClassifier()
model.fit(trainX.values, trainy.values)
yhat = model.predict(testX) ##crash