0
0
MLOpsdevops~10 mins

Automated testing for ML code in MLOps - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the testing library used for ML code.

MLOps
import [1]
Drag options to blanks, or click blank then click option'
Apytest
Btensorflow
Cnumpy
Dpandas
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ML libraries instead of testing libraries.
2fill in blank
medium

Complete the code to define a simple test function for ML model accuracy.

MLOps
def test_model_accuracy():
    accuracy = model.evaluate(X_test, y_test)[1]
    assert accuracy [1] 0.8
Drag options to blanks, or click blank then click option'
A==
B>=
C<=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality instead of comparison.
Using less than operator.
3fill in blank
hard

Fix the error in the test assertion to correctly check model loss is below threshold.

MLOps
def test_model_loss():
    loss = model.evaluate(X_val, y_val)[0]
    assert loss [1] 0.2
Drag options to blanks, or click blank then click option'
A>=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than operator.
Using equality operator.
4fill in blank
hard

Fill both blanks to create a test that checks if predictions shape matches labels shape.

MLOps
def test_prediction_shape():
    preds = model.predict(X_sample)
    assert preds.[1] == y_sample.[2]
Drag options to blanks, or click blank then click option'
Ashape
Bsize
Clen
Dndim
Attempts:
3 left
💡 Hint
Common Mistakes
Using size or length which may not match dimensions.
5fill in blank
hard

Fill all three blanks to write a test that filters valid predictions above threshold.

MLOps
valid_preds = [p for p in preds if p [1] [2]]
assert all(v [3] threshold for v in valid_preds)
Drag options to blanks, or click blank then click option'
A>
Bthreshold
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Confusing threshold with a number.