Before implementing early stopping, let's see how easy it is in Keras to monitor a loss that is calculated in a validation set; here, we will build another neural network for the diamond prices dataset:
nn_reg2 = Sequential()n_hidden = 64# hidden layersnn_reg2.add(Dense(units=n_hidden, activation='relu', input_shape=(n_input,)))nn_reg2.add(Dense(units=n_hidden, activation='relu'))nn_reg2.add(Dense(units=n_hidden, activation='relu'))nn_reg2.add(Dense(units=n_hidden, activation='relu'))nn_reg2.add(Dense(units=n_hidden, activation='relu'))nn_reg2.add(Dense(units=n_hidden, activation='relu'))# output layernn_reg2.add(Dense(units=1, activation=None))nn_reg2.compile(loss='mean_squared_error', optimizer='adam', metrics=['mse', ...