5. Compile model:
This step is used in Keras to to use the underlying libraries such as TensorFlow to find the best way to represent the network for training and implementation on your hardware. For compiling, you must specify some additional properties for training the network such as loss function, and optimization algorithm (optimizer). In this example, we will use mean squared error as the loss function, rmsprop as the optimizer [ref to Geoff Hinton's paper], and mean absolute error 'mae' as the evaluation measure:
kmodel.compile(loss='mean_squared_error',
optimizer='rmsprop',
metrics=[metrics.mae])
6. Fit/train model:
Once we compile the model, it is ready to be trained by data, remember that training is the process of tuning model parameters and weights. Similar to ScikitLearn, we can train a model using fit() function. During training, the model will go through the data for a fixed number of iterations. These iterations are called epochs and number of epochs is one of the properties of the training process for deep learning. You can also specify the number of instances evaluated before the network weights are updated. This is called batch_size
kmodel.fit(X_train, y_train, batch_size=100, epochs=500)
7. Evaluate model:
To evaluate the model on new data, we can use evaluate() function. Earlier in the compiling step, we specified mean absolute error as the metric to report the classification accuracy.
scores = kmodel.evaluate(X_test, y_test)
print("MAE: " + str(scores[1]))