← Lesson
BitWithBite
AI & Machine Learning · Quick Reference

lesson-1.4 Cheat Sheet

AI & Machine Learning
In one line: Both serialize Python objects to disk, but joblib is optimized for objects containing large NumPy arrays — exactly what most trained sklearn models are: weight matrices, support...

Key Ideas

1pickle vs joblib. Both serialize Python objects to disk, but joblib is optimized for objects containing large NumPy arrays — exactly what most trained sklearn models are: weight matrice...
2Save the whole pipeline, not just the model. If you save only the classifier and discard the scaler/encoder, you have a model that expects already-preprocessed input — but no record of how to preprocess new input...
3Version warnings and what breaks in production. Scikit-learn doesn't guarantee that a model pickled with one version loads cleanly in another. Internal object representations change between releases, especially majo...

Code Examples

import joblib joblib.dump(pipe, 'model.joblib') loaded_pipe = joblib.load('model.joblib') loaded_pipe.predict(X_new)
import sklearn, joblib metadata = {'sklearn_version': sklearn.__version__} joblib.dump({'pipeline': pipe, 'meta': metadata}, 'model.joblib') bundle = joblib.load('model.joblib') if bundle['meta']['sklearn_version'] != sklearn.__version__: print...