0
0
TensorFlowml~10 mins

Accuracy and loss monitoring 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 print the training accuracy after each epoch.

TensorFlow
model.fit(x_train, y_train, epochs=5, callbacks=[tf.keras.callbacks.LambdaCallback(on_epoch_end=lambda epoch, logs: print('Accuracy:', logs.get('[1]')))])
Drag options to blanks, or click blank then click option'
Aaccuracy
Bloss
Cval_loss
Dval_accuracy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'loss' instead of 'accuracy' to print accuracy.
Using validation keys like 'val_accuracy' when training accuracy is needed.
2fill in blank
medium

Complete the code to include validation loss monitoring during training.

TensorFlow
model.fit(x_train, y_train, epochs=10, validation_data=(x_val, y_val), callbacks=[tf.keras.callbacks.LambdaCallback(on_epoch_end=lambda epoch, logs: print('Validation Loss:', logs.get('[1]')))])
Drag options to blanks, or click blank then click option'
Aval_accuracy
Baccuracy
Closs
Dval_loss
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'loss' instead of 'val_loss' to get validation loss.
Using 'val_accuracy' when loss is needed.
3fill in blank
hard

Fix the error in the callback to correctly print validation accuracy.

TensorFlow
model.fit(x_train, y_train, epochs=3, validation_data=(x_val, y_val), callbacks=[tf.keras.callbacks.LambdaCallback(on_epoch_end=lambda epoch, logs: print('Val Accuracy:', logs.get('[1]')))])
Drag options to blanks, or click blank then click option'
Aval_accuracy
Bloss
Caccuracy
Dval_loss
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'accuracy' instead of 'val_accuracy' for validation accuracy.
Using 'val_loss' when accuracy is needed.
4fill in blank
hard

Fill both blanks to create a dictionary that stores training loss and validation accuracy after each epoch.

TensorFlow
history_dict = { 'train_loss': logs.get('[1]'), 'val_acc': logs.get('[2]') }
Drag options to blanks, or click blank then click option'
Aloss
Baccuracy
Cval_accuracy
Dval_loss
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up training and validation keys.
Using 'accuracy' instead of 'loss' for training loss.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores metric values greater than 0.5 from logs.

TensorFlow
filtered_metrics = {k: v for k, v in logs.items() if v [1] 0.5 and 'acc' [2] k and 'val' [3] k}
Drag options to blanks, or click blank then click option'
A>
Bin
Cnot in
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for value comparison.
Confusing 'in' and 'not in' for substring checks.