Skip to main content
Albero Academy

Saving & Loading Models

Persist a trained model and use it later or in production.

Applied Scikit-learn7 min

Training can be slow, and production needs the same model that was validated. Persisting a fitted pipeline lets you train once and reload instantly — the bridge from notebook to application.

joblib

save the whole pipeline
import joblib
joblib.dump(pipe, "model.joblib") # save the fitted pipeline
model = joblib.load("model.joblib") # reload later / in production
model.predict(new_data) # includes all preprocessing

Key takeaways

  1. 01joblib.dump/load persist a fitted model or pipeline to disk.
  2. 02Save the whole pipeline so preprocessing travels with the model.
  3. 03Pin scikit-learn versions — pickles aren't guaranteed across versions.
  4. 04Never load a model from an untrusted source (arbitrary-code risk).

Finished this chapter?

Mark it complete to track your progress through Scikit-learn.