0
0
ML Pythonml~10 mins

Saving and loading models in ML Python - Interactive Code Practice

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

Complete the code to save a trained model using joblib.

ML Python
import joblib

# Assume model is already trained
joblib.[1](model, 'model.pkl')
Drag options to blanks, or click blank then click option'
Aload
Bsave
Cdump
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load' instead of 'dump' to save the model.
Using 'save' which is not a joblib function.
2fill in blank
medium

Complete the code to load a saved model using joblib.

ML Python
import joblib

model = joblib.[1]('model.pkl')
Drag options to blanks, or click blank then click option'
Asave
Bload
Cdump
Dread
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dump' instead of 'load' to load the model.
Using 'save' which is not a joblib function.
3fill in blank
hard

Fix the error in saving a Keras model to HDF5 format.

ML Python
model.[1]('model.h5')
Drag options to blanks, or click blank then click option'
Awrite
Bload
Cdump
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dump' which is not a Keras model method.
Using 'load' instead of 'save'.
4fill in blank
hard

Fill both blanks to load a Keras model and evaluate it.

ML Python
from tensorflow.keras.models import [1]

model = [2]('model.h5')
loss, accuracy = model.evaluate(x_test, y_test)
Drag options to blanks, or click blank then click option'
Aload_model
Bsave_model
Cload
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'save_model' which is for saving, not loading.
Using 'load' which is not imported from keras.models.
5fill in blank
hard

Fill all three blanks to save a scikit-learn model, load it, and make predictions.

ML Python
import joblib

joblib.[1](model, 'model.pkl')
loaded_model = joblib.[2]('model.pkl')
predictions = loaded_model.[3](X_test)
Drag options to blanks, or click blank then click option'
Adump
Bload
Cpredict
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'save' instead of 'dump' to save the model.
Using 'load' incorrectly as a method on the model.
Using 'fit' instead of 'predict' to get predictions.