0
0
TensorFlowml~20 mins

First neural network in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Neural Network Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple neural network prediction
What is the output of the following code snippet that creates a simple neural network and predicts on a single input?
TensorFlow
import tensorflow as tf
import numpy as np

model = tf.keras.Sequential([
    tf.keras.layers.Dense(1, input_shape=(2,), activation='linear')
])

model.layers[0].set_weights([np.array([[1.0],[2.0]]), np.array([0.5])])

input_data = np.array([[3.0, 4.0]])
prediction = model.predict(input_data)
print(prediction)
A[[14.0]]
B[[11.5]]
C[[10.5]]
D[[7.5]]
Attempts:
2 left
💡 Hint
Remember the formula for a dense layer output: output = input * weights + bias.
Model Choice
intermediate
1:30remaining
Choosing the correct activation function for regression
You want to build a neural network to predict house prices (a continuous value). Which activation function should you use in the output layer?
ALinear
BSigmoid
CReLU
DSoftmax
Attempts:
2 left
💡 Hint
For continuous output without limits, choose an activation that does not restrict output range.
Hyperparameter
advanced
1:30remaining
Effect of batch size on training
Which statement best describes the effect of increasing batch size during neural network training?
ALarger batch sizes always improve model generalization.
BBatch size does not affect training speed or memory usage.
CIncreasing batch size reduces the number of training epochs needed but increases memory usage.
DSmaller batch sizes provide noisier gradient estimates but can improve generalization.
Attempts:
2 left
💡 Hint
Think about how batch size affects gradient noise and memory.
Metrics
advanced
1:30remaining
Choosing the right metric for classification
You train a neural network to classify images into 3 categories. Which metric is best to evaluate overall model accuracy?
AMean Absolute Error
BMean Squared Error
CAccuracy
DRoot Mean Squared Error
Attempts:
2 left
💡 Hint
Think about metrics that measure correct class predictions.
🔧 Debug
expert
2:30remaining
Identifying the cause of training failure
You train a neural network but the loss stays constant and does not decrease. What is the most likely cause?
TensorFlow
import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(10, activation='relu', input_shape=(5,)),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

model.compile(optimizer='adam', loss='binary_crossentropy')

import numpy as np
X = np.random.rand(100, 5)
y = np.ones((100, 1))

model.fit(X, y, epochs=10)
AThe labels y are all ones, causing no gradient to update weights.
BThe optimizer 'adam' is not suitable for binary classification.
CThe input shape is incorrect for the first layer.
DThe model uses sigmoid activation but binary_crossentropy loss, which is incompatible.
Attempts:
2 left
💡 Hint
Check if the labels provide enough variation for learning.