TransWikia.com

keras predicts nan values

Data Science Asked on October 15, 2020

I implemented a Keras model for my all-integer dataset with values greater than or equal to 0. The train data has dimensions of (393, 108) and prediction data has (1821, 108). Code is as follows.

import keras    
from keras.models import Sequential    
from keras.layers import Dense

X = data.iloc[:, :-1]
y = data.iloc[:, -1]

model = Sequential()
model.add(Dense(X.shape[1]-1, input_dim=X.shape[1], activation='tanh'))

for i in range(X.shape[1] - 2, 2, -100):
    model.add(Dense(i, activation='tanh'))

model.add(Dense(1, activation='tanh'))

opt = keras.optimizers.Adam(learning_rate=100)
model.compile(loss='categorical_crossentropy', optimizer=opt)
model.fit(X, y)
model.predict(X0)

I am getting all nan values as results.

array([[nan],
       [nan],
       [nan],
       ...,
       [nan],
       [nan],
       [nan]], dtype=float32)

One Answer

  • Your input is not standardized
  • The learning rate is way too high, start with the Default i.e. 0.001


Other suggested changes -

  • Use "relu" in the hidden/input layer
  • OHE the target
  • If the target is multi-class, the output layer should have same number of Neurons with softmax as activation
  • Data points are very less, Neural Net might not be the best option

Correct answer by 10xAI on October 15, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP