Test python models and functions deployed online with Cloud Pack for Data with form-formatted input data

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 image.png

It can be specified in JSON format. image.png

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.

How to save a model created in Python with an I / O schema

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']

Note: Changes from CP4D v3.0.1.

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

Test python models and functions deployed online with Cloud Pack for Data with form-formatted input data
Deploy functions with Cloud Pak for Data
This and that for using Step Functions with CDK + Python
Sensor data acquisition and visualization for plant growth with Intel Edison and Python
[GCP] Procedure for creating a web application with Cloud Functions (Python + Flask)
Data pipeline construction with Python and Luigi
Generate Japanese test data with Python faker
Try using Python with Google Cloud Functions
Use Python and MeCab with Azure Functions
Create test data like that with Python (Part 1)
Causal reasoning and causal search with Python (for beginners)
cv2 functions and data types (OpenCV python bindings)
[GCP] [Python] Deploy API serverless with Google Cloud Functions!
[Python for Hikari-] Chapter 06-04 Functions (arguments and return value 3)
Data analysis for improving POG 1 ~ Web scraping with Python ~
List of Python libraries for data scientists and data engineers
Benchmark for C, Java and Python with prime factorization
[PyTorch Tutorial ⑦] Visualizing Models, Data, And Training With Tensorboard
[Python for Hikari-] Chapter 06-01 Functions (Intrinsic Functions and Function Definitions)
Investigate Java and python data exchange with Apache Arrow
[Python for Hikari-] Chapter 06-03 Functions (arguments and return value 2)
Have Google Text-to-Speech create audio data (narration) for video material (with C # and Python samples)
[Python / Ruby] Understanding with code How to get data from online and write it to CSV