Deploy PMML models as online services for inference using the built-in processor.
Prerequisites
Models exported from Machine Learning Designer deploy directly to EAS. Models trained with open-source frameworks (scikit-learn, XGBoost) require conversion to PMML format before deployment. For conversion instructions, see Export a general-purpose model.
For PMML specification details, see PMML 4.4 - General Structure.
Missing value handling
If the PMML model file does not specify a missing value (isMissing) policy for features, the processor applies default values by data type.
|
Data type |
Default value |
|
BOOLEAN |
false |
|
DOUBLE |
0.0 |
|
FLOAT |
0.0 |
|
INT |
0 |
|
STRING |
"" |
Deploy the service
Set processor type to pmml in your configuration file when deploying with EASCMD.
{
"name": "eas_lr_example",
"processor": "pmml",
"model_path": "http://examplebucket.oss-cn-shanghai.aliyuncs.com/models/lr.pmml",
"metadata": {
"instance": 1,
"cpu": 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.
Call the service
Complete these steps to call the deployed service.
-
Go to Elastic Algorithm Service (EAS) page. Find your service and click View Invocation Method in Service Method column to obtain the endpoint and authentication token.
-
Construct a service request.
PMML service input and output must use JSON format. A single request can contain multiple samples with feature data in key-value format.
[ { "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 } ]NoteRemove line breaks and spaces from the JSON request to reduce network traffic and improve performance.
-
Send the service request.
Use one of these methods to send the request:
ImportantPassing the token in HTTP header transmits it in plaintext. Using EAS SDK signs the request with the token before transmission, providing higher security.
-
Use curl to test
Pass the authentication token in HTTP header when sending requests to the service endpoint.
// Send the request. 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}]'Parameters:
-
18284888792***.cn-shanghai.pai-eas.aliyuncs.com/api/predict/pmml_test: Replace with endpoint from Step 1.
-
Authorization: Replace with token from Step 1.
Sample response:
[{"p_0":0.2856724025030001,"p_1":0.7143275974969999},{"p_0":0.18324957921381624,"p_1":0.8167504207861838}] -
-
Use Python SDK. For SDK documentation, see Python SDK usage guide.
Example:
#!/usr/bin/env python from eas_prediction import PredictClient from eas_prediction import StringRequest if __name__ == '__main__': # Replace with endpoint and service name from Step 1. client = PredictClient('1828488879222***.cn-shanghai.pai-eas.aliyuncs.com', 'pmml_test') # Replace with 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.
-
Related information
-
For other processors, see Deploy a service using a pre-built processor.
-
For custom processor development, see Deploy a service using a custom processor.