CatBoost¶
About this page
This is an API reference for CatBoost in BentoML. Please refer to CatBoost guides for more information about how to use CatBoost in BentoML.
- bentoml.catboost.save_model(name: Tag | str, model: cb.CatBoost, *, signatures: dict[str, ModelSignatureDict] | None = None, labels: dict[str, str] | None = None, custom_objects: dict[str, t.Any] | None = None, external_modules: t.List[ModuleType] | None = None, metadata: dict[str, t.Any] | None = None) bentoml.Model¶
Save an CatBoost model instance to the BentoML model store.
- Parameters:
name – The name to give to the model in the BentoML store. This must be a valid
Tagname.model – The CatBoost model to be saved.
signatures – Signatures of predict methods to be used. If not provided, the signatures default to
{"predict": {"batchable": False}}. SeeModelSignaturefor more details.labels – A default set of management labels to be associated with the model. An example is
{"training-set": "data-1"}.custom_objects –
Custom objects to be saved with the model. An example is
{"my-normalizer": normalizer}.Custom objects are currently serialized with cloudpickle, but this implementation is subject to change.
external_modules (
List[ModuleType], optional, default toNone) – user-defined additional python modules to be saved alongside the model or custom objects, e.g. a tokenizer module, preprocessor module, model configuration modulemetadata –
Metadata to be associated with the model. An example is
{"max_depth": 2}.Metadata is intended for display in model management UI and therefore must be a default Python type, such as
strorint.
- Returns:
A
tagwith a format name:version where name is the user-defined model’s name, and a generated version by BentoML.- Return type:
Tag
Example:
import bentoml import numpy as np from catboost import CatBoostClassifier, Pool # initialize data train_data = np.random.randint(0, 100, size=(100, 10)) train_labels = np.random.randint(0, 2, size=(100)) test_data = catboost_pool = Pool(train_data, train_labels) model = CatBoostClassifier(iterations=2, depth=2, learning_rate=1, loss_function='Logloss', verbose=True) # train the model model.fit(train_data, train_labels) # save the model to the BentoML model store bento_model = bentoml.catboost.save_model("my_catboost_model", model)
- bentoml.catboost.load_model(bento_model: str | Tag | Model) catboost.CatBoost¶
Load the CatBoost model with the given tag from the local BentoML model store.
- Parameters:
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.- Returns:
The CatBoost model loaded from the model store or BentoML
Model.- Return type:
CatBoost
Example:
import bentoml # target model must be from the BentoML model store booster = bentoml.catboost.load_model("my_catboost_model")
- bentoml.catboost.get(tag: t.Union[Tag, str], *, _model_store: ModelStore = <simple_di.providers.SingletonFactory object>, model_aliases: t.Dict[str, str] = <simple_di.providers.Static object>) Model¶
Get a model by tag. If the tag is a string, it will be looked up in the model_aliases dict.
- bentoml.catboost.get_service(model_name: str, **config: Unpack[ServiceConfig]) Service[t.Any]¶
Get a BentoML service for the catboost model given by name.
- Parameters:
model_name (
str) – The name of the model to get the service for.**config (
Unpack[ServiceConfig]) – Configuration options for the service.
- Returns:
A BentoML service instance that wraps the CatBoost model.
Example:
import bentoml service = bentoml.catboost.get_service("my_catboost_model")