Home > Software design >  Keras model.fit() IndexError: list index out of range
Keras model.fit() IndexError: list index out of range

Time:10-20

I need some help, I keep getting this strange situation where my Keras model goes out of range

print(np.array(train_x).shape)
print(np.array(train_y).shape)

Returns:

(731, 42)
(731,)

Then:

normalizer = Normalization(input_shape=[42,], axis=None)
normalizer.adapt(train_x[0])

linear_model = Sequential([
    normalizer,
    Dense(units=1)
])
linear_model.summary()

Shows:

Model: "sequential_1"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
normalization_5 (Normalizati (None, 42)                3         
_________________________________________________________________
dense_1 (Dense)              (None, 1)                 43        
=================================================================
Total params: 46
Trainable params: 43
Non-trainable params: 3
_________________________________________________________________

Then:

linear_model.compile(
    optimizer=tf.optimizers.Adam(learning_rate=0.1),
    loss='mean_absolute_error')

linear_model.fit(
    train_x,
    train_y,
    epochs=100)

Which results in an IndexError: list index out of range. It looks like my inputs are in the right shape. Any idea what could be causing this?

CodePudding user response:

train_x and train_y needed to be numpy arrays.

  • Related