Create the layers
Import the Keras Libraries
- Import Sequential from keras.models
- Import Dense from keras.layers
Full Solution
# Importing the Keras libraries and packages from keras.models import Sequential from keras.layers import Dense
[collapse]
[collapse]
Create the Input Layer
- Instantiate Sequential in a variable named model.
- Create a Dense input layer with units of 8, activation of relu, input_dim set to the number of inputs per row in X, and give it the name Input_Layer.
Reference Material
https://keras.io/models/sequential/
Hint 1
Instantiate Sequential:
# Initilzing the ANN model = Sequential()
[collapse]
Hint 2
To add a Dense layer to your model try this:
model.add(Dense(???))
[collapse]
Full Solution
# Initilzing the ANN model = Sequential() #Adding the input layer model.add(Dense(units = 8, activation = 'relu', input_dim=X.shape[1], name= 'Input_Layer'))
[collapse]
[collapse]
Create the Hidden Layer
- Create a Dense input layer with units of 8, activation of relu, and give it the name Hidden_Layer_1.
Reference Material
https://keras.io/models/sequential/
Full Solution
#Add hidden layer model.add(Dense(units = 8, activation = 'relu', name= 'Hidden_Layer_1'))
[collapse]
[collapse]
Create the Output Layer
- Create a Dense output layer with units of 1, activation of sigmoid, and give it the name Output_Layer.
Reference Material
https://keras.io/models/sequential/
Full Solution
#Add the output layer model.add(Dense(units = 1, activation = 'sigmoid', name= 'Output_Layer'))
[collapse]
[collapse]
Compile the Model
- Use the compile method of Sequential to compile your model with the rmsprop optimizer, a binary_crossentropy loss function, with accuracy metrics.
Reference Material
https://keras.io/models/model/
Full Solution
# compiling the ANN model.compile(optimizer= 'rmsprop', loss = 'binary_crossentropy', metrics=['accuracy'])
[collapse]
[collapse]
Lab Complete!
Extra Credit – Loss Functions
Read More about CrossEntropy Loss
Other Keras Loss functions