Serialized Model Format#
serialize() turns a scikit-learn model into a plain dict, the same for every encoding
("json", "pickle", "msgpack", "yaml"). Format version: 4. For what each encoding
requires you to trust, see Security.
Example#
A fitted LogisticRegression, as JSON:
{
"estimator_class": "LogisticRegression",
"estimator_package": "sklearn",
"params": {
"C": 1.0, "class_weight": null, "dual": false, "fit_intercept": true,
"intercept_scaling": 1, "l1_ratio": 0.0, "max_iter": 100, "n_jobs": null,
"penalty": "deprecated", "random_state": null, "solver": "lbfgs",
"tol": 0.0001, "verbose": 0, "warm_start": false
},
"param_types": {
"C": "float", "class_weight": "NoneType", "dual": "bool", "fit_intercept": "bool",
"intercept_scaling": "int", "l1_ratio": "float", "max_iter": "int", "n_jobs": "NoneType",
"penalty": "str", "random_state": "NoneType", "solver": "str", "tol": "float",
"verbose": "int", "warm_start": "bool"
},
"param_dtypes": {},
"attributes": {
"classes_": [0, 1],
"coef_": [[1.9208796306558977, 1.6969321460065898, -0.47739463445708574, 0.2715726107798272]],
"intercept_": [-1.791565553734519],
"n_features_in_": 4,
"n_iter_": [8]
},
"attribute_types": {
"classes_": "ndarray", "coef_": "ndarray", "intercept_": "ndarray",
"n_features_in_": "int", "n_iter_": "ndarray"
},
"attribute_dtypes": {
"classes_": "int64", "coef_": "float64", "intercept_": "float64", "n_iter_": "int32"
},
"metadata": {
"producer_name": "openmodels",
"producer_version": "0.2.3",
"domain": "sklearn",
"domain_version": "1.9.1",
"packages": {"sklearn": "1.9.1"},
"openmodels_format_version": 4,
"created_at": "2026-10-08T06:19:40.587109+00:00",
"dependency_versions": {"python": "3.11.9", "numpy": "2.4.6", "scipy": "1.17.1"}
}
}
Estimator node#
Every model, and every estimator nested inside one, is a node with these fields.
Field |
Type |
Meaning |
|---|---|---|
|
|
Class name, e.g. |
|
|
Top-level package of the class: |
|
|
Constructor parameters ( |
|
|
Type tag of each param. |
|
|
dtype of each param that holds arrays. |
|
|
Fitted state: public attributes ending in |
|
|
Type tag of each attribute. |
|
|
dtype of each attribute that holds arrays. |
|
|
Root node only. |
Not stored, rebuilt on load: neighbors search trees, search estimators’ scorer_,
HistGradientBoosting*._loss/_n_features and LDA’s _max_components.
dtypes#
Value |
dtypes entry |
|---|---|
array |
its dtype text, e.g. |
list of arrays |
|
typed dict |
a dict of the same shape with its arrays’ dtypes |
Functions#
Rule |
|
|---|---|
Saved |
module and name; a bound method only if its module exposes it by name ( |
Loaded from |
already-imported modules of |
Refused |
private names, |
Metadata#
Field |
Type |
Meaning |
|---|---|---|
|
|
Tool that wrote the file ( |
|
|
That tool’s version. |
|
|
Framework the file targets: |
|
|
scikit-learn version of the file; a different installed version warns. |
|
|
|
|
|
|
|
|
ISO 8601 UTC time of |
|
|
Writer’s runtime ( |
|
|
Optional, user-supplied. |
|
|
Optional: |
|
|
Optional: e.g. |
Optional fields are passed as serialize(..., metadata={...}) or save(..., metadata={...}).
Encodings#
Encoding |
Notes |
|---|---|
JSON |
Tuples become lists. Non-finite floats are written as |
Pickle |
The dict as is, tuples included. |
msgpack, YAML |
Tuples become lists. |
Format versions#
openmodels reads every earlier version.
Version |
Written by openmodels |
Differences from 4 |
|---|---|---|
4 |
0.2.3 |
Current. |
3 |
0.2.2 |
No |
2 |
0.2.0, 0.2.1 |
As 3, plus: |
1 |
0.1.0 and its alphas |
As 2, plus: no |
openmodels 0.2.2 reads version 4 files with a warning, but loads typed dict values as plain JSON and non-string keys as strings, and can’t read per-element dtype lists.