Neural Network Workshop – Lab 5 Create the ANN

 

Create the layers

Import the Keras Libraries

  1. Import Sequential from keras.models
  2. 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

  1. Instantiate Sequential in a variable named model.
  2. 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/

https://keras.io/layers/core/

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

  1. 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/

https://keras.io/layers/core/

Full Solution
#Add hidden layer
model.add(Dense(units = 8, activation = 'relu', name= 'Hidden_Layer_1'))

[collapse]

[collapse]
Create the Output Layer

  1. 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/

https://keras.io/layers/core/

Full Solution
#Add the output layer
model.add(Dense(units = 1, activation = 'sigmoid', name= 'Output_Layer'))F

[collapse]

[collapse]
Compile the Model

  1. 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