Elastic Algorithm Service (EAS) includes built-in processors for gradient boosted decision tree (GBDT) algorithms — XGBoost and LightGBM. Deploy your GBDT models in supported formats as online services and run real-time inference through HTTP.
Prerequisites
Before you begin, ensure that you have:
An EAS-enabled PAI workspace
A trained XGBoost or LightGBM model stored in OSS, or a model exported from the GBDT or XGBoost component in Designer
The eascmd client installed and configured
For GBDT models exported from Designer, you can also deploy using the Predictive Model Markup Language (PMML) processor. See PMML processor for details.
Step 1: Deploy the service
Use the eascmd client to deploy the model. Set the processor field to xgboost or lightgbm in your configuration file.
Standard configuration:
{
"name": "gbdt_example",
"processor": "<processor_type>",
"model_path": "http://examplebucket.oss-cn-shanghai.aliyuncs.com/models/xgb_model.json",
"metadata": {
"instance": 1,
"cpu": 1
}
}Replace <processor_type> with xgboost or lightgbm.
Large model configuration:
For large models, the default processor compiles the model in memory and may run out of resources. Use a custom processor instead:
{
"name": "gbdt_example",
"processor_type": "python",
"processor_path": "https://eas-data.oss-cn-shanghai.aliyuncs.com/processors/xgboost_processor_notreelite.tar.gz",
"processor_entry": "xgboost_inference.py",
"model_path": "http://examplebucket.oss-cn-shanghai.aliyuncs.com/models/xgb_model.json",
"metadata": {
"instance": 1,
"cpu": 1
}
}For more information about deploying services with eascmd, see Service deployment: EASCMD & DSW.
Step 2: Call the service
Get your endpoint and token
Go to the Elastic Algorithm Service (EAS) page.
Find your service and click View Invocation Details in the Invocation Method column.
Copy the Endpoint and authentication token.
Request format
GBDT services accept and return JSON arrays. Each element in the outer array is one sample. A single request can contain multiple samples.
Example request body (2 samples, 30 features each):
[[14.87, 16.67, 98.64, 682.5, 0.1162, 0.1649, 0.169, 0.08923, 0.2157, 0.06768, 0.4266, 0.9489, 2.989, 41.18, 0.006985, 0.02563, 0.03011, 0.01271, 0.01602, 0.003884, 18.81, 27.37, 127.1, 1095.0, 0.1878, 0.448, 0.4704, 0.2027, 0.3585, 0.1065], [11.2, 29.37, 70.67, 386.0, 0.07449, 0.03558, 0.0, 0.0, 0.106, 0.05502, 0.3141, 3.896, 2.041, 22.81, 0.007594, 0.008878, 0.0, 0.0, 0.01989, 0.001773, 11.92, 38.3, 75.19, 439.6, 0.09267, 0.05494, 0.0, 0.0, 0.1566, 0.05905]]Remove line breaks and spaces from the JSON before sending. This reduces network traffic and improves performance.
Send the request
Choose the method that fits your workflow:
Option 1: Online debugging
Use the built-in online debugging tool in the EAS console to test the service directly in your browser.
Option 2: curl
Passing the token in the HTTP request header sends it as plaintext over the network. Use Option 3 (Python SDK) for more secure requests — the SDK signs the token before sending.
Pass your endpoint and token directly in the HTTP request header:
curl -v 18284888792***.cn-shanghai.pai-eas.aliyuncs.com/api/predict/eas_gbdt_example \
-H 'Authorization: YmE3NDkyMzdiMzNmMGM3ZmE4ZmNjZDk0M2NiMDA***' \
-d '[[14.87, 16.67, 98.64, 682.5, 0.1162, 0.1649, 0.169, 0.08923, 0.2157, 0.06768, 0.4266, 0.9489, 2.989, 41.18, 0.006985, 0.02563, 0.03011, 0.01271, 0.01602, 0.003884, 18.81, 27.37, 127.1, 1095.0, 0.1878, 0.448, 0.4704, 0.2027, 0.3585, 0.1065], [11.2, 29.37, 70.67, 386.0, 0.07449, 0.03558, 0.0, 0.0, 0.106, 0.05502, 0.3141, 3.896, 2.041, 22.81, 0.007594, 0.008878, 0.0, 0.0, 0.01989, 0.001773, 11.92, 38.3, 75.19, 439.6, 0.09267, 0.05494, 0.0, 0.0, 0.1566, 0.05905]]'Expected response:
[[0.0004703899612650275, 0.9877758026123047]]Option 3: Python SDK
The Python SDK signs the token before sending, which is more secure than passing it in the HTTP request header.
#!/usr/bin/env python
from eas_prediction import PredictClient
from eas_prediction import StringRequest
if __name__ == '__main__':
client = PredictClient('1828488879222***.cn-shanghai.pai-eas.aliyuncs.com', 'pmml_test')
client.set_token('YmE3NDkyMzdiMzNmMGM3ZmE4ZmNjZDk0M2NiMDA***')
client.init()
req = StringRequest('[[0.0004703899612650275,0.9877758026123047]]')
for x in range(100):
resp = client.predict(req)
print(resp)For SDKs in other languages, see Service invocation SDKs.