Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I tried using as many seeds as possible but I get a completely different result with my neural model. I also run classical Ml models such as Linear Regression or Random Forest but they are seeded and give me the same results each time.

---
SKlearn version: 0.24.2

Tensorflow version: 2.7.0

torch.cuda.is_available() is True
---

Here are my layers and fit() function:

Python
model = tf.keras.Sequential()
model.add(layers.Dense(32, activation='relu'))
model.add(layers.Dense(32, activation='relu'))
model.add(layers.Dense(32, activation='relu'))
model.add(layers.Dense(32, activation='relu'))
model.add(layers.Dense(32, activation='relu'))
model.add(layers.Dense(1))
model.compile(loss='huber', optimizer='adam', metrics=['mae', 'mse'])
history = model.fit(x=X_train, y=y_train, epochs=100, batch_size = 100, validation_data = (X_dev, y_dev), callbacks = [early_stopping])


What I have tried:

I import seeds at the top, and only once:

Python
np.random.seed(51)
tf.random.set_seed(51)
random.seed(51)
torch.manual_seed(51)
torch.cuda.manual_seed(51)
torch.cuda.manual_seed_all(51)
torch.backends.cudnn.deterministic = True


I put random_state in train_test_split:

Python
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 51, test_size = 0.4)
X_dev, X_test, y_dev, y_test = train_test_split(X_test, y_test, random_state = 51, test_size=0.5)

These are the only places that I used any kind of seeding or random state.
Posted
Updated 27-May-23 9:54am
v2
Comments
[no name] 9-Jan-22 13:28pm    
Are you loading a "new, clean" model with each iteration or just reusing?
Çağatay Ege Şahin 9-Jan-22 14:01pm    
I'm using Jupyter notebook and I have the same notebook file open. Each time I start from the beginning by importing the libraries, seeding, importing the data, preprocessing, splitting, training, evaluation. In that order.
[no name] 10-Jan-22 12:07pm    
If all's well, the implication is that there is still a seed somewhere that is defaulting to random.
Çağatay Ege Şahin 10-Jan-22 14:41pm    
It appears so. The code is really simple though. How do I find what causes that?
[no name] 11-Jan-22 19:13pm    
Totally unrelated but possibly related:

https://stackoverflow.com/questions/21494489/what-does-numpy-random-seed0-do

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900