I'm using the Boston Housing dataset in Keras, and neural networks for this regression problem.

The following is the code I use to prepare the data, build the model, and fit it with GridSearchCV.

from keras import models
from keras import layers
import numpy as np
from sklearn.model_selection import GridSearchCV
from keras.wrappers.scikit_learn import KerasRegressor
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import ShuffleSplit

from keras.datasets import boston_housing



def build_model():
    return model 


param_grid = {"epochs":range(1,11)}


When I run

grid_model.fit(train_data, train_targets)


several times, the performance seemed to vary a lot, with the MSE ranging from 60 to 90.

So, I thought that if I used ShuffleSplit, then maybe I could stabilise the scoring... For that, I've used this code:

ss = ShuffleSplit(n_splits=4, test_size=0.1, random_state=0)


grid_model.fit(train_data, train_targets)


However, now the MSE is even bigger! I've ran the last statement several times and I get an MSE ranging from 110 to 190. Not only it didn't stabilise, it also got worse. Why is that? Is my code incorrect somehow?

  • $\begingroup$ Try increasing the test size on the suffle split, since this is only .1 the variance of the estimates will be greater than the one that you see when running cv (default is 5 fold so your test size is 1/5 * X_train.shape[0] > than .1*X_train.shape[0] $\endgroup$ – Julio Jesus Mar 1 at 22:39
  • $\begingroup$ @JulioJesus thanks for the comment. I've tried that, but even with 0.20 or 0.5, the values were still of the same magnitude... $\endgroup$ – An old man in the sea. Mar 2 at 0:10
  • 1
    $\begingroup$ You might find this interesting: stats.stackexchange.com/questions/51416/… $\endgroup$ – Julio Jesus Mar 2 at 2:05
  • $\begingroup$ Finally I would like to add that, unless you are using a fixed seed on both cv method and model itself, another random factor will be added making difficult to get comparable results $\endgroup$ – Julio Jesus Mar 2 at 2:09
  • $\begingroup$ @JulioJesus and thanks for the link ;) $\endgroup$ – An old man in the sea. Mar 2 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.