Complete the code to import the testing library used for ML code.
import [1]
The pytest library is commonly used for automated testing in Python, including ML code.
Complete the code to define a simple test function for ML model accuracy.
def test_model_accuracy(): accuracy = model.evaluate(X_test, y_test)[1] assert accuracy [1] 0.8
The test checks if the model accuracy is at least 0.8, so the operator should be >=.
Fix the error in the test assertion to correctly check model loss is below threshold.
def test_model_loss(): loss = model.evaluate(X_val, y_val)[0] assert loss [1] 0.2
The test should assert that loss is less than 0.2, so the operator is <.
Fill both blanks to create a test that checks if predictions shape matches labels shape.
def test_prediction_shape(): preds = model.predict(X_sample) assert preds.[1] == y_sample.[2]
Both predictions and labels have a shape attribute that shows their dimensions, so we compare those.
Fill all three blanks to write a test that filters valid predictions above threshold.
valid_preds = [p for p in preds if p [1] [2]] assert all(v [3] threshold for v in valid_preds)
The list comprehension filters predictions greater than the threshold, and the assertion checks all are greater or equal to it.