0
0
TensorFlowml~10 mins

Multi-class classification model in TensorFlow - 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 multi-class classification model using TensorFlow Keras.

TensorFlow
model = tf.keras.Sequential([
    tf.keras.layers.Dense(64, activation='relu', input_shape=(input_shape,)),
    tf.keras.layers.Dense(10, activation=[1])
])
Drag options to blanks, or click blank then click option'
A'sigmoid'
B'linear'
C'softmax'
D'tanh'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sigmoid' activation which is for binary classification.
Using 'linear' activation which does not output probabilities.
2fill in blank
medium

Complete the code to compile the multi-class classification model with the correct loss function.

TensorFlow
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
A'categorical_crossentropy'
B'binary_crossentropy'
C'mean_squared_error'
D'hinge'
Attempts:
3 left
💡 Hint
Common Mistakes
Using binary_crossentropy which is for binary classification.
Using mean_squared_error which is for regression tasks.
3fill in blank
hard

Fix the error in the code to correctly prepare labels for multi-class classification training.

TensorFlow
y_train_encoded = tf.keras.utils.to_categorical([1], num_classes=10)
Drag options to blanks, or click blank then click option'
AX_train
BX_test
Cy_test
Dy_train
Attempts:
3 left
💡 Hint
Common Mistakes
Encoding input features instead of labels.
Encoding test labels instead of training labels.
4fill in blank
hard

Fill both blanks to train the model with the encoded labels and set the number of epochs.

TensorFlow
history = model.fit(X_train, [1], epochs=[2], batch_size=32, validation_split=0.2)
Drag options to blanks, or click blank then click option'
Ay_train_encoded
By_test_encoded
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using test labels for training.
Setting epochs too low or too high without reason.
5fill in blank
hard

Fill all three blanks to evaluate the model on test data and print the accuracy.

TensorFlow
loss, accuracy = model.evaluate([1], [2], batch_size=32)
print(f"Test accuracy: [3]")
Drag options to blanks, or click blank then click option'
AX_test
By_test_encoded
Caccuracy
Dloss
Attempts:
3 left
💡 Hint
Common Mistakes
Using training data for evaluation.
Printing loss instead of accuracy.