Introduction to Deep Learning with Keras
Miguel Esteban
Data Scientist & Founder
# Store initial model weights init_weights = model.get_weights()
# Lists for storing accuracies train_accs = [] tests_accs = []
for train_size in train_sizes: # Split a fraction according to train_size X_train_frac, _, y_train_frac, _ = train_test_split(X_train, y_train, train_size=train_size)
# Set model initial weights model.set_weights(initial_weights)
# Fit model on the training set fraction model.fit(X_train_frac, y_train_frac, epochs=100, verbose=0, callbacks=[EarlyStopping(monitor='loss', patience=1)])
# Get the accuracy for this training set fraction train_acc = model.evaluate(X_train_frac, y_train_frac, verbose=0)[1] train_accs.append(train_acc)
# Get the accuracy on the whole test set test_acc = model.evaluate(X_test, y_test, verbose=0)[1] test_accs.append(test_acc) print("Done with size: ", train_size)
Introduction to Deep Learning with Keras