Skip to content Skip to sidebar Skip to footer

Keras Fitting Ignoring Nan Values

I am training a neural network to do regression, (1 input and 1 output). Let's x and y be the usual input and output dataset, respectively. My problem is that the y dataset (not th

Solution 1:

As said in the comments, simply remove the nan as a preprocessing step:

import numpy as np

x = range(2,8)
y = [4,2,np.nan,7,np.nan,np.nan]

for a,b inzip(x,y):
    ifstr(b) == 'nan':
        x.remove(a)
        y.remove(b)

print x,y

produces [2, 3, 5] [4, 2, 7].

If you're using some tool to preprocess the data which gives you the np.nan, check whether the API allows you to disable this behavior and take a minute to think whether this is really the behavior you want (or if you e.g. want to map this to constants because you find your input to be valuable even though they have no labels).

Post a Comment for "Keras Fitting Ignoring Nan Values"