0
0
ML Pythonml~10 mins

Neural network architecture in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple neural network layer using Keras.

ML Python
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

model = Sequential()
model.add(Dense([1], input_shape=(10,), activation='relu'))
Drag options to blanks, or click blank then click option'
ASequential
B'relu'
C10
D32
Attempts:
3 left
💡 Hint
Common Mistakes
Using the activation function name instead of the number of neurons.
Using the input shape as the number of neurons.
2fill in blank
medium

Complete the code to compile the model with the correct loss function for classification.

ML Python
model.compile(optimizer='adam', loss='[1]', metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
Acategorical_crossentropy
Bmean_absolute_error
Cmean_squared_error
Dhinge
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean squared error loss for classification.
Using hinge loss which is for SVMs.
3fill in blank
hard

Fix the error in the code to add a dropout layer with 0.5 dropout rate.

ML Python
from tensorflow.keras.layers import Dropout

model.add(Dropout([1]))
Drag options to blanks, or click blank then click option'
A50
B0.5
C5
D1.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 50 instead of 0.5 for dropout rate.
Using values greater than 1.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps layer names to their output shapes for layers with output shape length greater than 2.

ML Python
layer_shapes = {layer.name: layer.output_shape for layer in model.layers if len(layer.output_shape) [1] [2]
Drag options to blanks, or click blank then click option'
A>
B2
C<
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using 1 instead of 2 as the threshold.
5fill in blank
hard

Fill all three blanks to create a dictionary that maps layer names in uppercase to their output shapes, but only for layers with output shape length greater than 1.

ML Python
layer_info = {layer.name[1]: layer.output_shape for layer in model.layers if len(layer.output_shape) [2] [3]
Drag options to blanks, or click blank then click option'
A.upper()
B>
C1
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Not using .upper() to convert names.
Using '<' instead of '>' in the condition.
Using 2 instead of 1 as the threshold.