Scikit-Learn#

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.

Note

You can find more examples for Scikit-Learn in our BentoML/examples directory.

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

Save a model instance to BentoML modelstore.

Parameters:
  • name – Name for given model instance. This should pass Python identifier check.

  • model – Instance of model to be saved.

  • signatures – Methods to expose for running inference on the target model. Signatures are used for creating Runner instances when serving model with bentoml.Service

  • labels – user-defined labels for managing models, e.g. team=nlp, stage=dev

  • custom_objects – user-defined additional python objects to be saved alongside the model, e.g. a tokenizer instance, preprocessor function, model configuration json

  • external_modules – user-defined additional python modules to be saved alongside the model or custom objects, e.g. a tokenizer module, preprocessor module, model configuration module

  • metadata – Custom metadata for given model.

Returns:

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

Return type:

Tag

Examples:

import bentoml

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

model = KNeighborsClassifier()
iris = load_iris()
X = iris.data[:, :4]
Y = iris.target
model.fit(X, 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.

Parameters:

bento_model – Either the tag of the model to get from the store, or a BentoML ~bentoml.Model instance to load the model from.

Returns:

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

Example:

import bentoml
sklearn = bentoml.sklearn.load_model('my_model:latest')
bentoml.sklearn.get(tag_like: str | Tag) Model[source]#