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.
- 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.
- Parameters
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 toNone
) โ user-defined labels for managing models, e.g. team=nlp, stage=devcustom_objects (
Dict[str, Any]]
, optional, default toNone
) โ- 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 toNone
) โ 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
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
- Returns
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โ)