Compiling the Keras model
The model built in the previous sections needs to be compiled with the model.compile()
method before it can be used for training and prediction. The full signature of the compile()
method is as follows:
compile(self, optimizer, loss, metrics=None, sample_weight_mode=None)
The compile method takes three arguments:
optimizer
: You can specify your own function or one of the functions provided by Keras. This function is used to update the parameters in the optimization iterations. Keras offers the following built-in optimizer functions:SGD
RMSprop
Adagrad
Adadelta
Adam
Adamax
Nadam
loss
: You can specify your own loss function or use one of the provided loss functions. The optimizer function optimizes the parameters so that the output of this loss function is minimized. Keras provides the following loss functions:mean_squared_error
mean_absolute_error
mean_absolute_pecentage_error
mean_squared_logarithmic_error
squared_hinge
hinge
categorical_hinge
sparse_categorical_crossentropy
binary_crossentropy...