scikit-learn
Use this when the artifact is an estimator, pipeline, or tree model rather than a deep-learning checkpoint.
When to use scikit-learn
Use scikit-learn when you need to:
- load persisted estimators or pipelines from
joblibor pickle files - inspect parameters, pipeline stages, and feature handling
- read feature importances or linear coefficients
- export or reason about decision-tree structure
Quick Start
import joblib
model = joblib.load("model.joblib")
print(type(model))
print(model.get_params().keys())
High-Value Workflows
Pipeline inspection
if hasattr(model, "named_steps"):
print(model.named_steps)
if hasattr(model, "get_feature_names_out"):
print(model.get_feature_names_out())
Feature importance or coefficients
if hasattr(model, "feature_importances_"):
print(model.feature_importances_)
if hasattr(model, "coef_"):
print(model.coef_)
Tree export helpers
from sklearn.tree import export_text
if hasattr(model, "tree_"):
print(export_text(model))
Practical Notes
joblibis the common persistence format for sklearn models with large NumPy arrays.- Pipelines often carry more insight than the final estimator alone, so inspect
named_stepsearly. feature_names_in_andget_feature_names_out()are high-value clues when reconstructing model inputs.- For untrusted
.pkl/.joblibartifacts, preferskops.io(skops.io.dump/skops.io.load) — it persists without pickle and forces explicittrusted=[...]allowlisting of any non-primitive types on load, converting the silent RCE surface of pickle into a visible whitelist decision.
import skops.io as sio
untrusted = sio.get_untrusted_types(file="model.skops")
print(untrusted) # inspect what the file wants to instantiate
model = sio.load("model.skops", trusted=untrusted) # only after review
Caveats
joblib.loadand pickle are unsafe for untrusted files.- Cross-version loading is not guaranteed to be stable.
- Some estimators expose rich introspection, while others offer almost none beyond
get_params().
Resources
No bundled scripts/, references/, or assets/.
Use the official scikit-learn persistence and pipeline docs for version and API specifics.