Day 5 - Using the Keras Sequential API
- Sequential API can be used to create the simplest kind of neural networks: composed of a single stack of layers connected sequentially.
-
The first layer can be a
Flatten
layer (which converts multidimensional input e.g. an image into a 1-dimensional array) or anInputLayer
.
- Each dense layer has its own matrix of connection weights between the neurons and their inputs, and a vector of bias terms per neuron.
-
The shape of the weight matrix depends on the number of inputs. If
the input shape is not specified in the first layer, Keras will wait
until the
build()
method is called or training is started to infer the input size.
- Until the input size is known, operations like printing the model summary or saving the model cannot be performed.
- After a model is built, it needs to be compiled with: optimizer to use (e.g. sgd), the loss function to use, and a list of extra metrics to compute during training and evaluation.
Using the Sequential API for Classification
-
If the labels are sparse (i.e. a target class index is used for each
data point) and the classes are exclusive, use the
sparse_categorical_crossentropy
loss function.
-
If the labels are one-hot encoded vectors, use the
categorical_crossentropy
loss function.
-
If the training set is skewed, the
class_weight
orsample_weight
arguments can be used.
Google Colaboratory

Using the Sequential API for Regression
- Output layer has a single neuron with no activation function.
- Mean Squared Error used as a loss function.
Google Colaboratory
