Home > Net >  Epoch loss, mean absolute error and validation loss is "nan" for machine learning time ser
Epoch loss, mean absolute error and validation loss is "nan" for machine learning time ser

Time:11-06

I am applying Time Series modelling from here for another dataset. For the given dataset in the link, all the losses (namely loss, mean absolute error, validation loss, mean absolute error for validation; The last two losses are not for all epoch models) computed in the epochs are non zero, whereas when I change the dataset all the loss values are nan. The dataset I use has approximately half the number of readings compared to that of the dataset being used here. My dataset has readings that are recorded from multiple locations (40 odd locations) at the same time at 15 minutes interval.

The training function for all the procedures is defined as

MAX_EPOCHS = 20

def compile_and_fit(model, window, patience=2):
  early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss',
                                                    patience=patience,
                                                    mode='min')

  model.compile(loss=tf.keras.losses.MeanSquaredError(),
                optimizer=tf.keras.optimizers.Adam(),
                metrics=[tf.keras.metrics.MeanAbsoluteError()])

  history = model.fit(window.train, epochs=MAX_EPOCHS,
                      validation_data=window.val,
                      callbacks=[early_stopping])
  return history

I have also tried running the model by changing model.compile to

  opt = tf.keras.optimizers.Adam(0.001, clipnorm=1.)
  model.compile(loss=["mse", "mse"], loss_weights=[0.9, 0.1], optimizer=opt)

by looking at solutions for similar problem. The batch size for my dataset is 4654 whereas that of the dataset in the given notebook is 1534.

How to solve this issue to get the non zero losses?

Also, I am unable to get predictions for all the models except baseline model.

CodePudding user response:

Using this code snippet to change NaNs to 0's and then verifying this gives me the value of loss and validation loss.

df.replace(np.nan, 0.0, inplace=True) 
df.isnull().values.any()#check if nan are still there

PS: Thanks for the help in the comments!

  • Related