python
11 lines · 1 tab
Dr. Elena Vasquez
Apr 2026
1 tab
import joblib
from skl2onnx import to_onnx
from skl2onnx.common.data_types import FloatTensorType
joblib.dump(model, 'artifacts/model.joblib')
initial_types = [('features', FloatTensorType([None, X_train.shape[1]]))]
onnx_model = to_onnx(model, initial_types=initial_types, target_opset=17)
with open('artifacts/model.onnx', 'wb') as file_handle:
file_handle.write(onnx_model.SerializeToString())
1 file · python
Explain with highlit
Model serialization is not just a file-format choice. It affects startup time, compatibility, portability, and security boundaries. I use joblib for common scikit-learn pipelines, reserve pickle for trusted internal workflows, and reach for ONNX when I need cross-runtime portability.
Related snips
python
import mlflow
import mlflow.sklearn
from sklearn.metrics import roc_auc_score
mlflow.set_experiment('customer-churn')
Experiment tracking and model registry workflows with MLflow
mlflow
experiment-tracking
model-registry
by Dr. Elena Vasquez
1 tab
python
import joblib
import pandas as pd
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(title='Churn Prediction API')
Serving scikit-learn models behind a FastAPI prediction API
fastapi
scikit-learn
model-serving
by Dr. Elena Vasquez
1 tab
python
import great_expectations as gx
context = gx.get_context()
data_source = context.data_sources.add_pandas(name='training_data')
asset = data_source.add_dataframe_asset(name='churn_asset')
batch_definition = asset.add_batch_definition_whole_dataframe('full_dataframe')
Great Expectations checks for dataset health before retraining
great-expectations
data-quality
mlops
by Dr. Elena Vasquez
1 tab
Share this code
Here's the card — post it anywhere.