Hi Ottonemo,
Thank you very much for the quick response. My training dataset is like this:
tensor([[ 50., 50., 50., 50.],
[ 50., 50., 50., 50.],
[ 50., 50., 50., 51.],
…,
[169., 169., 169., 170.],
[169., 169., 170., 170.],
[169., 170., 170., 170.]])
tensor([[ 50., 50., 50., 50.],
[ 50., 50., 50., 51.],
[ 50., 50., 51., 52.],
…,
[169., 169., 170., 170.],
[169., 170., 170., 170.],
[170., 170., 170., 170.]])
My main code is like this:
PyTorch LSTM regressor
class AirModel(nn.Module):
def init(self):
super().init()
self.lstm = nn.LSTM(input_size=1, hidden_size=50, num_layers=1, batch_first=True)
self.linear = nn.Linear(50, 1)
def forward(self, x):
x, _ = self.lstm(x)
x = self.linear(x)
return x
creat the skorch wrapper
model_skorch=NeuralNetRegressor(
module=AirModel,
criterion=nn.MSELoss,
optimizer=optim.Adam,
verbose=True)
param_grid={
‘batch_size’:[8,10],
‘max_epochs’:[500],
}
grid search in Scikit-learn
grid = GridSearchCV(estimator=model_skorch, param_grid=param_grid, n_jobs=-1, cv=3,error_score=‘raise’)
grid_result = grid.fit(X_train, y_train)
But there is always a error in the last row of code: “input.size(-1) must be equal to input_size. Expected 1, got 4”
I appreciate any comments about it