#!/usr/bin/env python # coding: utf-8 # ### Introduction # # After we have created a model we will typically want to save it as a binary file so it can be deployed for prediction. # # Seldon core is a model deployment engine. Here is an excerpt from the seldon documentation for Scikit-learn deployments # # > Seldon expects that your model has been saved using joblib, and it named as model.joblib. Note that this is the recommended approach to serialise models by the SKLearn project. # > # > _Source: https://docs.seldon.io/projects/seldon-core/en/latest/servers/sklearn.html_ # ### Saving a model # # Here we use the [joblib](https://joblib.readthedocs.io/en/latest/persistence.html) Python library to save a model: # In[8]: # set the random state to make the examples repeatable import numpy as np np.random.seed(1) from sklearn.datasets import load_iris from sklearn.svm import LinearSVC iris = load_iris() X, y = iris.data, iris.target classifier = LinearSVC() model = classifier.fit(X, y) from joblib import dump, load dump(model, 'iris_model.joblib') # We can execute a shell command with `!`. Let's inspect the saved file: # In[9]: get_ipython().system(' ls -l iris_model.joblib') # ### Summary # # More information on model persistence can be found in the Scikit-learn [docs](https://scikit-learn.org/stable/modules/model_persistence.html#) # --- # # ### Navigation # # [Previous](./09_model_performance.ipynb) | [Home](./00-README-FIRST.ipynb) | [Next](./11_model_predictions.ipynb) notebook # In[ ]: