About this page

This is an API reference for using Scikit-Learn in BentoML. Please refer to Scikit-Learn Guide for more information about how to use Scikit-learn in BentoML.

bentoml.sklearn.save_model(name: str, model: SklearnModel, *, signatures: ModelSignaturesType | None = None, labels: t.Dict[str, str] | None = None, custom_objects: t.Dict[str, t.Any] | None = None, metadata: t.Dict[str, t.Any] | None = None) bentoml.Model[source]#

Save a model instance to BentoML modelstore.

  • name (str) โ€“ Name for given model instance. This should pass Python identifier check.

  • model (Union[BaseEstimator, Pipeline]) โ€“ Instance of model to be saved.

  • ( (signatures) โ€“

    code: Dict[str, ModelSignatureDict]) Methods to expose for running inference on the target model. Signatures are

    used for creating Runner instances when serving model with bentoml.Service

  • labels (Dict[str, str], optional, default to None) โ€“ user-defined labels for managing models, e.g. team=nlp, stage=dev

  • custom_objects (Dict[str, Any]], optional, default to None) โ€“

    user-defined additional python objects to be saved alongside the model,

    e.g. a tokenizer instance, preprocessor function, model configuration json

  • metadata (Dict[str, Any], optional, default to None) โ€“ Custom metadata for given model.


A tag with a format name:version where name is the user-defined modelโ€™s name, and a generated version.

Return type



import bentoml

from sklearn.datasets import load_iris
from sklearn.neighbors import KNeighborsClassifier

model = KNeighborsClassifier()
iris = load_iris()
X =[:, :4]
Y =, Y)

bento_model = bentoml.sklearn.save_model('kneighbors', model)
bentoml.sklearn.load_model(bento_model: str | Tag | Model) SklearnModel[source]#

Load the scikit-learn model with the given tag from the local BentoML model store.

  • bento_model (str | Tag | Model) โ€“ Either the tag of the model to get from the store, or a BentoML ~bentoml.Model instance to load the model from.

  • ... โ€“


The scikit-learn model loaded from the model store or BentoML Model.

Return type

BaseEstimator | Pipeline

Example: .. code-block:: python

import bentoml sklearn = bentoml.sklearn.load_model(โ€˜my_model:latestโ€™)

bentoml.sklearn.get(tag_like: str | Tag) Model[source]#