0
$\begingroup$

enter image description here

I have set my numpy random seed to 0. I am training on colab and using keras. I didn't change anything. I just re-ran my cell and the val_absolute_error changed.

Code:

np.random.seed(0)
regressor = Sequential()
regressor.add(Dense(10, input_dim=1, activation='tanh'))
regressor.add(Dense(20, input_dim=1, activation='relu'))
regressor.add(Dense(15, input_dim=1, activation='tanh'))
regressor.add(Dense(1))
regressor.compile(optimizer='adam', loss='mean_absolute_error', metrics=['mae'])
model = regressor.fit(X_train, y_train, epochs=450, batch_size=10, validation_data=(X_val, y_val), verbose=1)

print(regressor.evaluate(X_test, y_test)) --> This is the error on the test set

Please note that I made a mistake in the screenshot, it is the error in test set not val. set

$\endgroup$
  • $\begingroup$ Do you set the random seed before splitting the data into training set and test set? If you use train_test_split from scikit-learn the split will be randomised. $\endgroup$ – louic May 26 at 18:17
  • $\begingroup$ May I add: the test/train split is different (pseudo random) if you dont fix the random state by using a seed. Also the model results are non-deterministic. For fully reproduceable results, alway choose a random state via setting a seed. $\endgroup$ – Peter May 26 at 19:01
1
$\begingroup$

I think you need this one too:

from tensorflow import set_random_seed
set_random_seed(123)
$\endgroup$
0
$\begingroup$

have you checked the versions of the libraries you're using? I use % pip freeze to check. Perhaps there is something inconsistent that causes this difference. It looks like you've already got your seed set, so you're good there.

If it turns out to be a difference in the libraries, consider exporting the environment from one system and set your environment in the other to use those versions of your libraries.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.