I have designed the following Binary Classifier Neural Network Model for a task. I want to add an early stopper to the model so that the model stops at an epoch where it has stopped learning significantly. How can I do that?
Model
X = badge1_data[['1','2','3','Score']]
y = badge1_data['APR']
#Standardizing the Input Features
scaler = StandardScaler()
X = scaler.fit_transform(X)
#Train Test split
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.3)
#Create Model
model = Sequential()
model.add(Dense(4,
input_dim=4,
kernel_initializer='normal',
activation='relu'))
model.add(Dense(2,
kernel_initializer='normal',
activation='relu'))
model.add(Dense(1,
activation='sigmoid',
kernel_initializer='normal'))
#Compile Model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
#Fit Model
model.fit(X_train, y_train, epochs = 5000, validation_split = 0.3, verbose=0, batch_size=256)
#Make predictions and convert to binary value
pred_train = model.predict(X_train)
pred_test = model.predict(X_test)
#ROC AUC Score
print('Train AUC = {:}'.format(roc_auc_score(y_train,pred_train)))
print('Test AUC = {:}'.format(roc_auc_score(y_test,pred_test)))
#Accuracy
print('Train Accuracy = ',accuracy_score(y_train,pred_train.round()))
print('Test Accuracy = ',accuracy_score(y_test,pred_test.round()))