Complete the code to import the mean squared error loss from TensorFlow.
from tensorflow.keras.losses import [1]
The correct import for mean squared error loss function in TensorFlow Keras is MeanSquaredError class.
Complete the code to compile a model using mean squared error loss.
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
To use mean squared error as the loss function, specify 'mean_squared_error' as the loss parameter.
Fix the error in the code to use sparse categorical cross-entropy loss correctly.
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
The correct loss function for sparse categorical labels is 'sparse_categorical_crossentropy'.
Fill both blanks to create a model with binary cross-entropy loss and sigmoid activation.
model = tf.keras.Sequential([
tf.keras.layers.Dense(1, activation=[1])
])
model.compile(optimizer='adam', loss=[2], metrics=['accuracy'])Binary classification models use sigmoid activation and binary cross-entropy loss.
Fill all three blanks to define a custom loss function using mean squared error.
import tensorflow as tf def custom_loss(y_true, y_pred): return tf.keras.losses.[1](y_true, y_pred) model.compile(optimizer='adam', loss=[2], metrics=[[3]])
The custom loss calls mean_squared_error function. The compile loss is the string name. Accuracy is a common metric.