- Published on
- Authors
- Name
- KAUSTUBH SHARMA
PreRequisite
- You need to Read about How to Train the Model(only 1 min. read).
STEP-1: Create Deployable Model Endpoint
- First, we will import CSVSerializer class from the SageMaker SDK, which will help us to serialize input data in CSV format.
- Also, we will create an object "xgb_predictor" as a SageMaker Predictor, representing deployed model endpoint. We can use this object to make predictions on new data.
from sagemaker.serializers import CSVSerializer
xgb_predictor=xgb_model.deploy(
initial_instance_count=1,
instance_type='ml.t2.medium',
serializer=CSVSerializer()
)
where
xgb_model.deploy: Method used to deploy trained XGBoost model as an endpoint on SageMaker for making predictions.
initial_instance_count=1: Specifies initial number of instances (containers) to deploy. In our case, we set it to 1.
instance_type='ml.t2.medium': Specifies type of compute instance to use for hosting the model.
serializer=CSVSerializer(): Specifies serializer to be used for input data of various formats (a NumPy array, list, file, or buffer). The CSVSerializer is chosen, indicating that input data should be formatted as CSV.
The deploy method creates a deployable model, configures the SageMaker hosting services endpoint, and launches the endpoint to host the model.
STEP-2: Retrive Endpoint Name
xgb_predictor.endpoint_name
- This will return the endpoint name of the xgb_predictor. The format of the endpoint name is "sagemaker-xgboost-YYYY-MM-DD-HH-MM-SS-SSS".