Using a validation set

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', ...

Get Hands-On Predictive Analytics with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.