Skip to content

Prevent overfitting #19

@lukaszog

Description

@lukaszog

Hi,
I train your model on one midi file and I split data into test and valid. Next I plot test/valid and I see that model is overfit. Did you known how to prevent this?

# build a 2 stacked LSTM
  model = Sequential()
  model.add(LSTM(128, return_sequences=True, input_shape=(max_len, N_values)))
  model.add(Dropout(0.2))
  model.add(LSTM(128, return_sequences=False))
  model.add(Dropout(0.2))
  model.add(Dense(N_values))
  model.add(Activation('softmax'))

  model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])

  history = model.fit(X, y, batch_size=128, nb_epoch=N_epochs, validation_split=0.22)

  print(history.history.keys())

  # acc history
  plt.plot(history.history['acc'])
  plt.plot(history.history['val_acc'])
  plt.title('model accuracy')
  plt.ylabel('accuracy')
  plt.xlabel('epoch')
  plt.legend(['train', 'test'], loc='upper left')
  plt.savefig("acc_history.png")
  plt.close()

  plt.plot(history.history['loss'])
  plt.plot(history.history['val_loss'])
  plt.title('model loss')
  plt.ylabel('loss')
  plt.xlabel('epoch')
  plt.legend(['train', 'test'], loc='upper left')
  plt.savefig("history_loss.png")


  return history

acc_history
history_loss

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions