Deploy PMML models as online inference services using the built-in PMML processor in Elastic Algorithm Service (EAS).
Prerequisites
Before you begin, ensure that you have:
A PMML model file. Models exported from Machine Learning Designer deploy directly to EAS without conversion. Models trained with scikit-learn or XGBoost require conversion to PMML format first — see Export a general-purpose model
(Optional) Familiarity with the PMML 4.4 general structure if you need to inspect or modify your model file
Deploy the service
Set "processor": "pmml" in your configuration file and specify the path to your model:
{
"name": "eas_lr_example",
"processor": "pmml",
"model_path": "http://examplebucket.oss-cn-shanghai.aliyuncs.com/models/lr.pmml",
"metadata": {
"instance": 1,
"cpu": 1
}
}Configuration parameters:
| Parameter | Description | Example |
|---|---|---|
name | Service name | eas_lr_example |
processor | Processor type. Set to pmml for PMML models. | pmml |
model_path | URL of the .pmml model file | http://examplebucket.oss-cn-shanghai.aliyuncs.com/models/lr.pmml |
metadata.instance | Number of service instances | 1 |
metadata.cpu | Number of CPU cores per instance | 1 |
For EASCMD deployment instructions, see Deploy a service using EASCMD or DSW. To deploy from the console, see Deploy a service from the console.
Missing value handling
If the PMML model does not define an isMissing policy for a feature, the processor applies these defaults:
| Data type | Default value |
|---|---|
| BOOLEAN | false |
| DOUBLE | 0.0 |
| FLOAT | 0.0 |
| INT | 0 |
| STRING | "" |
Call the service
Step 1: Get the endpoint and token
Go to the Elastic Algorithm Service (EAS) page. Find your service and click View Invocation Method in the Service Method column to get the endpoint URL and authentication token.
Step 2: Construct the request
PMML services accept and return JSON. A single request can contain multiple samples, each as a JSON object with feature key-value pairs:
[
{"address": 12, "age": 22, "ed": 4, "marital": 3.0, "region": 2.0, "tenure": 4.0},
{"address": 2, "age": 34, "ed": 6, "marital": 1.3, "region": 2.1, "tenure": 4.2}
]Remove line breaks and spaces from the JSON before sending to reduce network traffic and improve throughput.
Step 3: Send the request
Two methods are available. Using the EAS SDK signs the request with the token before transmission, providing higher security.
Use curl
Pass the authentication token in the Authorization header:
curl -v 18284888792***.cn-shanghai.pai-eas.aliyuncs.com/api/predict/pmml_test \
-H 'Authorization: YmE3NDkyMzdiMzNmMGM3ZmE4ZmNjZDk0M2NiMDA***' \
-d '[{"region": 2.0, "marital":3.0,"tenure":4.0, "age":22,"address":12,"ed":4},{"region": 2.1, "marital":1.3,"tenure":4.2, "age":34,"address":2,"ed":6}]'Replace 18284888792***.cn-shanghai.pai-eas.aliyuncs.com/api/predict/pmml_test with your endpoint from step 1, and replace the Authorization value with your token.
The token is transmitted in plaintext with curl. Using the EAS SDK signs the request with the token before transmission, providing higher security.
Sample response:
[{"p_0":0.2856724025030001,"p_1":0.7143275974969999},{"p_0":0.18324957921381624,"p_1":0.8167504207861838}]Use the Python SDK
The SDK signs each request with the token before transmission, providing higher security than passing the token in plaintext.
#!/usr/bin/env python
from eas_prediction import PredictClient
from eas_prediction import StringRequest
if __name__ == '__main__':
# Replace with your endpoint and service name from step 1.
client = PredictClient('1828488879222***.cn-shanghai.pai-eas.aliyuncs.com', 'pmml_test')
# Replace with your token from step 1.
client.set_token('YmE3NDkyMzdiMzNmMGM3ZmE4ZmNjZDk0M2NiMDA***')
client.init()
req = StringRequest('[{"region": 2.0, "marital":3.0,"tenure":4.0, "age":22,"address":12,"ed":4},{"region": 2.1, "marital":1.3,"tenure":4.2, "age":34,"address":2,"ed":6}]')
for x in range(100):
resp = client.predict(req)
print(resp)For SDKs in other languages, see Service invocation SDKs. For Python SDK documentation, see Python SDK usage guide.
What's next
For other pre-built processors, see Deploy a service using a pre-built processor.
To build a custom inference environment, see Deploy a service using a custom processor.