From the course: Deep Learning: Getting Started
Creating a deep learning model
- [Instructor] Let's now define a model for the Iris problem. We will continue on the same Iris notebook as before for creating the model. This video is covered in section 4.3. When we say we are creating a model in Keras, we are merely defining the architecture and hyperparameters for the neural network. Training of the model itself will happen later. Once a model is defined this way, it can be trained and retrained any number of times. We start off by defining the number of classes in the target variable. Note that we have used one-hot encoding on the target variables before. We now proceed to create a sequential model in Keras. We can now start adding layers to the model. We add the first hidden layer of 128 nodes. This is a number we can experiment with as we improve the model. Then, we define the input shape. Since we know that we have four input variables, we define the same here. We can provide a logical name for the layer that is helpful in printing information later. We will use rectified linear unit activation for this layer. We continue to add another hidden layer, Hidden-Layer-2. We will again have 128 nodes, and then activation of relu. Finally, we add the output layer. Here, the number of nodes will be equal to the number of classes in the target variable. We will use softmax activation to predict the probabilities of each class for the input provided. Then, we will compile the model. For loss computation, we will use categorical_crossentropy, since this is a multi-class classification model. We will also use accuracy as the metric to measure loss. There are a number of other parameters to compile the model, but we have assumed the default values. We will discuss more of these in the model optimization and tuning course. Finally, we print the model summary. Let's execute this code block. We see the model summary being printed here. It shows each layer and the shape of the output. It also shows the total number of parameters in the model, which are the weights and biases across the two hidden and one output layer. Please refer to the earlier video on weights and biases on how the number of parameters is determined.