Complete the code to compile the TensorFlow model with the correct loss function.
model.compile(optimizer='adam', loss=[1], metrics=['accuracy'])
The 'sparse_categorical_crossentropy' loss is used for multi-class classification with integer labels, which fits many classification tasks.
Complete the code to fit the model on training data for 10 epochs.
history = model.fit(x_train, y_train, epochs=[1], validation_split=0.2)
Training for 10 epochs is a common choice to balance learning and overfitting.
Fix the error in the code to evaluate the model on test data and get accuracy.
test_loss, [1] = model.evaluate(x_test, y_test)The model.evaluate returns loss and metrics in order; here, the second value is accuracy as specified during compile.
Fill both blanks to create a confusion matrix and print it.
from sklearn.metrics import [1] cm = [2](y_test, y_pred) print(cm)
The confusion_matrix function from sklearn.metrics computes the confusion matrix, which helps evaluate classification reliability.
Fill all three blanks to calculate precision, recall, and F1-score.
from sklearn.metrics import [1], [2], [3] precision = [1](y_test, y_pred) recall = [2](y_test, y_pred) f1 = [3](y_test, y_pred) print(f"Precision: {precision}\nRecall: {recall}\nF1-score: {f1}")
Precision, recall, and F1-score are key metrics to evaluate classification models thoroughly for reliability.