If you deploy the model to the Online type in the deployment space of Cloud pak for Data (CP4D), you can test the operation on the deployment details screen. As a method of specifying the sample input data to be used for test execution, specify in the following form format and
It can be specified in JSON format.
To use the form format, you need to create the model with an input schema. Models created with Modeler Flow (SPSS) seem to have an input schema automatically, but models created with Python need to specify the input schema as meta information when saving with WML client.
The following code saves the scikit-learn model created using the WML client in the deployment space. For how to use WML client, refer to this article.
The form format requires only the input schema, but it also has an output schema.
For models
meta_props={
client.repository.ModelMetaNames.NAME: "sample_iris_model",
client.repository.ModelMetaNames.RUNTIME_UID: "scikit-learn_0.22-py3.6",
client.repository.ModelMetaNames.TYPE: "scikit-learn_0.22",
client.repository.ModelMetaNames.INPUT_DATA_SCHEMA: [{
"id":"input",
"type":"list",
"fields":[
{'name': 'sepal length (cm)', 'type': 'double'},
{'name': 'sepal width (cm)', 'type': 'double'},
{'name': 'petal length (cm)', 'type': 'double'},
{'name': 'petal width (cm)', 'type': 'double'}
]
}],
client.repository.ModelMetaNames.OUTPUT_DATA_SCHEMA: {
"id":"output",
"fields": [
{'name': 'iris_type', 'type': 'string','metadata': {'modeling_role': 'prediction'}}
]
}
}
model_artifact = client.repository.store_model(model, meta_props=meta_props, training_data=X, training_target=y)
model_id = model_artifact['metadata']['guid']
function(function)in the case of
meta_props = {
client.repository.FunctionMetaNames.NAME: 'sample_iris_scoring_func',
client.repository.FunctionMetaNames.RUNTIME_UID: "ai-function_0.1-py3.6",
client.repository.FunctionMetaNames.SPACE_UID: space_id,
client.repository.FunctionMetaNames.INPUT_DATA_SCHEMAS: [{
"id":"input",
"fields": [
{"metadata": {}, "type": "double", "name": "sepal length (cm)", "nullable": False},
{"metadata": {}, "type": "double", "name": "sepal width (cm)", "nullable": False},
{"metadata": {}, "type": "double", "name": "petal length (cm)", "nullable": False},
{"metadata": {}, "type": "double", "name": "petal width (cm)", "nullable": False}
]
}],
client.repository.FunctionMetaNames.OUTPUT_DATA_SCHEMAS: [{
"id":"output",
"fields": [
{"metadata": {'modeling_role': 'prediction'}, "type": "string", "name": "iris_type", "nullable": False}
]
}]
}
function_details = client.repository.store_function(meta_props=meta_props, function=iris_scoring)
function_id = function_details['metadata']['guid']
Strictly speaking, it's a change from WML client version v1.0.95, not CP4D version. CP4D v3.0.1 includes WML client v1.0.95 by default.
The change is that the model input schema is now specified as a list type instead of a dict type. The above sample code specifies INPUT_DATA_SCHEMA as a list type. This change seems to correspond to multiple input data tables, but since it was specified as dict type before v1.0.95, even if dict type is specified in v1.0.99 or later for backward compatibility It has been fixed so that it does not cause an error.
In addition, when I tried it, an error occurred even if I specified it as a list type in v1.0.95. (This is inquiring with this) It works well with v1.0.103, so we recommend upgrading with `` `pip install -U watson-machine-learning-client-V4``` before using it.
Recommended Posts