Skip to content

Getting Started

Installation

pip install skeights

For LightGBM or XGBoost support:

pip install skeights[lightgbm]
pip install skeights[xgboost]
pip install skeights[all]  # both

Compatibility

Requires scikit-learn >= 1.5, LightGBM >= 4.4 (optional), XGBoost >= 2.1 (optional). CI tests against scikit-learn 1.5, 1.6, and latest; LightGBM 4.4 and latest; XGBoost 2.1 and latest.

Models saved with older versions of skeights can generally be loaded by newer versions, but cross-version compatibility is not guaranteed. skeights will emit a warning when loading a model saved with a different library version.

Save and load

import skeights
from sklearn.linear_model import Ridge
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler

pipe = Pipeline([
    ("scaler", StandardScaler()),
    ("model", Ridge(alpha=0.1)),
])
pipe.fit(X_train, y_train)

# Save to files
skeights.save(pipe, "model.safetensors", "model.json")

# Load back
loaded = skeights.load("model.safetensors", "model.json")
predictions = loaded.predict(X_test)

In-memory serialization

If you don't want to write to disk (e.g. for storing in a database or sending over the network):

state, arrays = skeights.serialize(pipe)

# Later...
loaded = skeights.deserialize(state, arrays)

Inspecting hyperparameters

get_model_params recursively extracts hyperparameters from an estimator. For pipelines, it walks each step and returns a nested dict, so you get a complete view of every parameter in the entire pipeline.

params = skeights.get_model_params(pipe)
# {"steps": {
#     "scaler": {"with_mean": True, "with_std": True,
#                "type": "sklearn.preprocessing.StandardScaler", ...},
#     "model":  {"alpha": 0.1, "fit_intercept": True,
#                "type": "sklearn.linear_model.Ridge", ...}
#  }, ...}

set_model_params lets you update parameters using the same nested structure. This is useful for modifying a deserialized model without refitting it.

skeights.set_model_params(pipe, {"steps": {"model": {"alpha": 0.5}}})