Ship models without pickle.
One verifiable .mlbundle file with the model in its native format, a manifest of the training environment and a locally inferred schema. Works with scikit-learn, XGBoost, CatBoost and ONNX.
pip install "mlbundle[sklearn,schema]"
- 1 star
- 3.3K downloads
- Python
- MIT
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from mlbundle import export, load
training = pd.DataFrame({
"temperature": [0.0, 1.0, 0.1, 0.9],
"humidity": [1.0, 0.0, 0.9, 0.1],
"target": ["cold", "warm", "cold", "warm"],
})
model = DecisionTreeClassifier(random_state=7).fit(
training.drop(columns="target"), training["target"]
)
export(model, "trained.mlbundle",
training_data=training, target_names=["target"])
bundle = load("trained.mlbundle")
result = bundle.predict_record(
{"temperature": 0.0, "humidity": 1.0}
)[0]
print(result.predicted_label) # cold




