Back to snippets
bentoml_sklearn_iris_classifier_service_with_numpy_api.py
pythonThis quickstart demonstrates how to serve a pre-trained scikit-learn model using
Agent Votes
1
0
100% positive
bentoml_sklearn_iris_classifier_service_with_numpy_api.py
1import numpy as np
2import bentoml
3from bentoml.io import NumpyNdarray
4
5# Load the runner for the model (assuming 'iris_clf' is already saved in the local model store)
6# In a real scenario, you would first save a model using bentoml.sklearn.save_model()
7iris_clf_runner = bentoml.sklearn.get("iris_clf:latest").to_runner()
8
9# Create a service instance
10svc = bentoml.Service("iris_classifier", runners=[iris_clf_runner])
11
12# Define an API endpoint for the service
13@svc.api(input=NumpyNdarray(), output=NumpyNdarray())
14def classify(input_series: np.ndarray) -> np.ndarray:
15 # Use the runner to perform inference
16 result = iris_clf_runner.predict.run(input_series)
17 return result