How to do it...

We'll now build a single model with the Keras library:

  1. Build a linear stack of layers with the sequential model:
# building a linear stack of layers with the sequential modelmodel = Sequential()model.add(Dense(512, input_shape=(1024,)))model.add(Activation('relu')) model.add(Dense(512))model.add(Activation('relu'))model.add(Dense(10))model.add(Activation('softmax'))
  1. Compile the model:
# compiling the sequential modelmodel.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')
  1. Fit the model to the train data and validate it with the test data:
# training the model and saving metrics in historysvhn_model = model.fit(x_train, y_train,          batch_size=128, epochs=100,          verbose=2, validation_data=(x_test, ...

Get Ensemble Machine Learning Cookbook 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.