Guest User

Untitled

a guest
Jan 16th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. # Train and test over multiple train/validation sets
  2. early_stop = keras.callbacks.EarlyStopping(monitor='val_loss', min_delta=0, patience=5, verbose=2, mode='auto', restore_best_weights=False)
  3. sss2 = StratifiedShuffleSplit(n_splits=10, test_size=0.2, random_state=1).split(train_x, train_labels)
  4. for i in range(10):
  5. train_indices_2, val_indices = next(sss2)
  6. model = getModel()
  7. model.fit(x=train_x[train_indices_2], y=train_labels[train_indices_2], epochs=50, batch_size=32, shuffle=True, validation_data = (train_x[val_indices], train_labels[val_indices]), verbose=2, callbacks=[early_stop])#Line7
  8. test_loss, test_accuracy = model.evaluate(test_x, test_labels, verbose=2)
  9. print (test_loss, test_accuracy)
  10. predicted = model.predict(test_x, verbose=2)
  11. predicted_labels = predicted.argmax(axis=1)
  12. print (confusion_matrix(labels[test_indices], predicted_labels))
  13. print (classification_report(labels[test_indices], predicted_labels, digits=4, target_names=namesInLabelOrder))
Add Comment
Please, Sign In to add comment