Welcome to IBM Watson OpenScale Python SDK’s 3.0.26 documentation!

Python client library to quickly get started with IBM Watson OpenScale. ibm_watson_openscale is a python library that allows to work with Watson OpenScale service on IBM Cloud. Test and deploy your models as APIs for application development, share with colleagues using this python library.

Installation

The package is available on pypi. To install, use pip:

$pip install -U ibm-watson-openscale

Requirements

Watson OpenScale service instance, you can create instance using this link. Only Python 3.5 or newer is supported. ibm-cloud-sdk-core >= 1.1 is required to be able to authenticate to the service.

Breaking changes log

  • Watson Machine Learning instances in regions other than US-South (Dallas) are not officially supported.

  • Only one deployment per subscription is supported.

Supported engines

  • Watson Machine Learning

  • Custom Machine Learning (following this specification)

  • Microsoft Azure Machine Learning Studio (deployments of type new)

  • Amazon SageMaker Machine Learning

  • SPSS Collaboration and Deployment Services

API

To start working with the client library you need Watson OpenScale service credentials. Credentials can be found under Credentials tab of your service instance (IBM Cloud). An OpenScale Python SDK v2 uses an ibm-cloud-sdk-core package to authenticate with the service. For more detailed description of the authentication, please visit: IBM Cloud SDK Core

Below is presented the programmatically version of client initialization. All necessary credentials must be provided during APIClient object creation. Only authenticator parameter is required, but have in mind that passing only authenticator parameter, the default options will be used (service_url = “https://api.aiopenscale.cloud.ibm.com” and service_instance_id will be retrieved automatically)

from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_watson_openscale import APIClient

service_credentials = {
                  "apikey": "*****",
                  "url": "https://api.aiopenscale.cloud.ibm.com"
               }

authenticator = IAMAuthenticator(
        apikey=service_credentials['apikey']
    )

# default value of service_url = "https://api.aiopenscale.cloud.ibm.com",
# service_instance_id retrieved automatically
client = APIClient(
        authenticator=authenticator
    )

# or

# service_instance_id retrieved automatically
client = APIClient(
    service_url=service_credentials['url'],
    authenticator=authenticator
)

# or

client = APIClient(
    service_url=service_credentials['url'],
    service_instance_id="230a8e9f-2453-4c2d-a560-2a75399210bf"
    authenticator=authenticator
)

In case of CP4D environments, CloudPakForDataAuthenticator class should be used (instead of IAMAuthenticator)

from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator
from ibm_watson_openscale import APIClient

service_credentials = {
                "url": "******",
                "username": "*****",
                "password": "*****"
                }

authenticator = CloudPakForDataAuthenticator(
        url=service_credentials['url'],
        username=service_credentials['username'],
        password=service_credentials['password'],
        disable_ssl_verification=True
    )

# default value of service_url = "https://api.aiopenscale.cloud.ibm.com",
# service_instance_id retrieved automatically
client = APIClient(
        authenticator=authenticator
    )

# or

# service_instance_id retrieved automatically
client = APIClient(
    service_url=service_credentials['url'],
    authenticator=authenticator
)

# or

client = APIClient(
    service_url=service_credentials['url'],
    service_instance_id="230a8e9f-2453-4c2d-a560-2a75399210bf"
    authenticator=authenticator
)

# or

#
# Use this if you have CP4D 4.0.x and iam integration is enabled.
# bedrock_url is nothing but the foundational services (common-services-route ) url. User needs to get this url from CP4D admin.
client = APIClient(
    service_url=service_credentials['url'],
    service_instance_id="230a8e9f-2453-4c2d-a560-2a75399210bf"
    authenticator=authenticator,
    bedrock_url = <COMMON_SERVICES_URL>
)

You could initialize the client from environmental variables directly or from configuration file. The service_name must be identical in the configuration file and passed to the new_instance() class method of the client

File with configuration:

# bm-credentials.env
OpenScale_URL=https://api.aiopenscale.cloud.ibm.com
OpenScale_AUTH_TYPE=iam
OpenScale_APIKEY=ncn92u92benfi2nec0292ebicm02
OpenScale_AUTH_URL=https://iam.cloud.ibm.com/identity/token

How to use new_instance() class method:

from ibm_watson_openscale import APIClient
import os

os.environ["IBM_CREDENTIALS_FILE"] = "path_to_credential_file/ibm-credentials.env"
ai_client = APIClient.new_instance(service_name='OpenScale')

Basic SDK’s elements

APIClient

class WatsonOpenScaleV2Adapter(authenticator: Optional[Union[BearerTokenAuthenticator, CloudPakForDataAuthenticator, IAMAuthenticator, CloudPak40ForDataAuthenticator]] = None, service_url: Optional[str] = None, service_instance_id: Optional[str] = None, bedrock_url: Optional[str] = None)[source]

Bases: WatsonOpenScaleV2

Watson OpenScale client.

Variables

#:var business_applications: Manages business_applications module #:vartype business_applications: ibm_watson_openscale.business_applications.BusinessApplications

A way you might use me is:

>>> from ibm_watson_openscale import APIClient
>>> client = APIClient(authenticator=authenticator, service_url=service_url) # client will use default service_instance_id
>>> client = APIClient(authenticator, service_url) # client will use default service_url and default service_instance_id
>>> client = APIClient(authenticator=authenticator, service_url=service_url, service_instance_id=service_instance_id)
>>> client = APIClient(authenticator=authenticator, service_url=service_url, service_instance_id=service_instance_id,bedrock_url=bedrock_url )
>>> client = APIClient(authenticator, service_url, service_instance_id)
classmethod new_instance(service_name: Optional[str] = None) WatsonOpenScaleV2Adapter[source]

This class method should be used only if you have stored your credentials in the separate file or in the ENV variable.

Parameters

service_name – Unique name of the service to configure.

Returns

ibm_watson_openscale.APIClient

A way you might use me is:

>>> from ibm_watson_openscale import APIClient
>>> client = APIClient.new_instance(service_name="openscale-1")
>>> client = APIClient.new_instance(service_name="openscale-2")
>>> client = APIClient.new_instance("openscale")

APIClient.data_marts

class DataMarts(ai_client: WatsonOpenScaleV2Adapter)[source]

Bases: DataMarts

Manages Database instance.

show(limit: Optional[int] = 10) None[source]

Show Data marts. By default 10 records will be shown.

Parameters

limit (int) – Maximal number of fetched rows. By default set to 10. (optional)

A way you might use me is:

>>> client.data_marts.show()
>>> client.data_marts.show(limit=20)
>>> client.data_marts.show(limit=None)
add(name: str = None, description: str = None, service_instance_crn: str = None, internal_database: bool = None, database_configuration: DatabaseConfigurationRequest = None, force: bool = None, background_mode: bool = True) DetailedResponse[source]

Add the data mart. Configure database connection for the data mart.

Parameters
  • name (str) – (optional) Name of the data mart.

  • description (str) – (optional) Description of the data mart.

  • service_instance_crn (str) – (optional) Can be omitted if user token is used for authorization.

  • internal_database (bool) – (optional) If true the internal database managed by AI OpenScale is provided for the user.

  • database_configuration (DatabaseConfigurationRequest) – (optional) Database configuration ignored if internal database is requested (internal_database is true).

  • force (bool) – (optional) force update of metadata and db credentials (assumption is that the new database is already prepared and populated).

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataMartDatabaseResponse result

A way you might use me is:

>>> from ibm_watson_openscale import *
>>> client.data_marts.add(
        background_mode=False,
        name="My Data Mart",
        description="Description of the data mart...",
        database_configuration=DatabaseConfigurationRequest(
            database_type='postgresql',
            instance_id='crn:v1:bluemix:public:databases-for-postgresql:us-south:a/***',
            credentials=PrimaryStorageCredentialsLong(
                hostname='some hostname',
                username='some username',
                password='some password',
                db='database name',
                port=50000,
                ssl=True,
                sslmode='verify-full',
                certificate_base64='***'
            ),
            location=LocationSchemaName(
                schema_name='name of the database schema'
            )
        )
     )
delete(data_mart_id: str, force: bool = None, background_mode: bool = True) DetailedResponse[source]

Delete the data mart.

Parameters
  • data_mart_id (str) – ID of the data mart.

  • force (bool) – (optional) force hard delete.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

A way you might use me is:

>>> client.data_marts.delete(
        background_mode=False,
        data_mart_id='id of the datamart',
        force=True
     )
get(data_mart_id: str, **kwargs) DetailedResponse[source]

Get data mart with the given id.

Parameters
  • data_mart_id (str) – ID of the data mart.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataMartDatabaseResponse result

list(**kwargs) DetailedResponse[source]

List all data marts.

The method returns the data mart confugrations as an object.

Parameters

headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataMartDatabaseResponseCollection result

patch(data_mart_id: str, json_patch_operation: List[JsonPatchOperation], **kwargs) DetailedResponse[source]

Update a data mart.

Parameters
  • data_mart_id (str) – ID of the data mart.

  • json_patch_operation (List[JsonPatchOperation]) –

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataMartDatabaseResponse result

APIClient.service_providers

class ServiceProviders(ai_client: WatsonOpenScaleV2Adapter)[source]

Bases: ServiceProviders

Manages Service Provider instance.

show(limit: Optional[int] = 10, show_deleted: Optional[bool] = None, service_type: Optional[str] = None, instance_id: Optional[str] = None, operational_space_id: Optional[str] = None, deployment_space_id: Optional[str] = None, **kwargs) None[source]

Show service providers. By default 10 records will be shown.

Parameters
  • limit (int) – maximal number of fetched rows. By default set to 10. (optional)

  • show_deleted (bool) – (optional) show also resources pending delete.

  • service_type (str) – (optional) Type of service.

  • instance_id (str) – (optional) comma-separeted list of IDs.

  • operational_space_id (str) – (optional) comma-separeted list of IDs.

  • deployment_space_id (str) – (optional) comma-separeted list of IDs.

  • headers (dict) – A dict containing the request headers

A way you might use me is:

>>> client.service_providers.show()
>>> client.service_providers.show(limit=20)
>>> client.service_providers.show(limit=None)
add(name: str, service_type: str = None, description: str = None, credentials: MLCredentials = None, request_headers: object = None, operational_space_id: str = None, deployment_space_id: str = None, group_ids: List[str] = None, user_ids: List[str] = None, background_mode: bool = True) DetailedResponse[source]

Add service provider.

Assosiate external Machine Learning service instance with the OpenScale DataMart.

Parameters
  • name (str) – Name of the ML service instance.

  • service_type (str) – (optional) machine learning service type (azure_machine_learning_studio is a preferred alias for azure_machine_learning and should be used in new service bindings).

  • description (str) – (optional)

  • credentials (MLCredentials) – (optional)

  • request_headers (object) – (optional) map header name to header value.

  • operational_space_id (str) – (optional) Reference to Operational Space. Allowed values are ‘production’ and ‘pre_production’

  • deployment_space_id (str) – (optional) Reference to V2 Space ID

  • group_ids (List[str]) – (optional) Access control list of group id of Cloud Pak for Data (Only available for OpenScale on Cloud Pak for Data >= 4.0.6 with ENABLE_GROUP_AUTH being true).

  • user_ids (List[str]) – (optional) Access control list of user id of Cloud Pak for Data (Only available for OpenScale on Cloud Pak for Data >= 4.0.6 with ENABLE_GROUP_AUTH being true).

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with ServiceProviderResponse result

A way you may use me when WML is located on same cluster

>>> from ibm_watson_openscale import *
>>> added_service_provider_info = client.service_providers.add(
        background_mode=False,
        name="WML instance",
        service_type=ServiceTypes.WATSON_MACHINE_LEARNING,
        deployment_space_id = <SPACE_ID>,
        operational_space_id = "production"
        credentials=WMLCredentialsCloud(
            url='<URL>',
            username='<USERNAME>',
            password='<PASSWORD>'
        )
     )

A way you may use me when WML is located on different CP4D cluster (Available only on CP4D 4.0 or higher)

>>> from ibm_watson_openscale import *
>>> from ibm_watson_openscale.supporting_classes.enums import *
>>> added_service_provider_info = client.service_providers.add(
        background_mode=False,
        name="WML instance",
        service_type=ServiceTypes.WATSON_MACHINE_LEARNING,
        deployment_space_id = <SPACE_ID>,
        operational_space_id = "production"
        credentials=WMLCredentialsCloud(
            url = '<URL>',
            username='<USERNAME>,
            apikey='APIKEY>',
            wml_location = CP4DWMLLocation.CPD_REMOTE
        )
     )

A way you may use me when WML is located on IBM Cloud

>>> from ibm_watson_openscale import *
>>> from ibm_watson_openscale.supporting_classes.enums import *
>>> added_service_provider_info = client.service_providers.add(
        background_mode=False,
        name="WML instance",
        service_type=ServiceTypes.WATSON_MACHINE_LEARNING,
        deployment_space_id = <SPACE_ID>,
        operational_space_id = "production"
        credentials=WMLCredentialsCloud(
            url = '<URL>',
            apikey='APIKEY>',
            wml_location = CP4DWMLLocation.CLOUD_REMOTE
        )
     )
delete(service_provider_id: str, force: bool = None, background_mode: bool = True) DetailedResponse[source]

Delete service provider.

Detach Machine Learning service provider.

Parameters
  • service_provider_id (str) – ID of the ML service provider.

  • force (bool) – (optional) force hard delete.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

A way you may use me:

>>> client.service_providers.delete(
        background_mode=False,
        service_provider_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        force=True
     )
list_assets(data_mart_id: str, service_provider_id: str, deployment_id: Optional[str] = None, deployment_space_id: Optional[str] = None) Response[source]

Listing all deployments and assets for specific data_mart and service_provider.

Parameters
  • data_mart_id (str) – ID of the data_mart (required)

  • service_provider_id (str) – ID of the service_provider (required)

  • deployment_id (str) – ID of the deployment (optional), when used, only specific deployment is returned

  • deployment_space_id (str) – (optional) Reference to V2 Space ID

Returns

Response

A way you may use me:

>>> response = client.service_providers.list_assets(
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        service_provider_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        deployment_space_id='6574djd4-00d2-4g05-ac02-287ebfc603b5'
     )
>>> print(response.result)
 {'count': 1,
 'resources': [{'entity': {'asset': {'asset_id': '997b1474-00d2-4g05-ac02-287ebfc603b5',
                                     'asset_type': 'model',
                                     'created_at': '2020-01-13T09:15:26.586Z',
                                     'name': 'AIOS Spark Credit Risk model',
                                     'url': 'https://us-south.ml.cloud.ibm.com/v3/wml_instances/997b1474-00d2-4g05-ac02-287ebfc603b5/published_models/997b1474-00d2-4g05-ac02-287ebfc603b5'},
                           'asset_properties': {'asset_revision': '997b1474-00d2-4g05-ac02-287ebfc603b5',
                                                'input_data_schema': {'fields': [{'metadata': {},
                                                                                  'name': 'CheckingStatus',
                                                                                  'nullable': True,
                                                                                  'type': 'string'},
                                                                                 ...
                                                'label_column': 'Risk',
                                                'model_type': 'mllib-2.3',
                                                'runtime_environment': 'spark-2.3',
                                                'training_data_schema': {'fields': [{'metadata': {},
                                                                                     'name': 'CheckingStatus',
                                                                                     'nullable': True,
                                                                                     'type': 'string'},
                                                                                    ...
                           'description': 'Description of deployment',
                           'name': 'AIOS Spark Credit Risk deployment',
                           'scoring_endpoint': {'url': 'https://us-south.ml.cloud.ibm.com/v3/wml_instances/997b1474-00d2-4g05-ac02-287ebfc603b5/deployments/997b1474-00d2-4g05-ac02-287ebfc603b5/online'},
                           'type': 'online'},
                'metadata': {'created_at': '2020-01-13T09:15:26.607Z',
                             'guid': '997b1474-00d2-4g05-ac02-287ebfc603b5',
                             'modified_at': '2020-01-13T09:15:26.848Z',
                             'url': 'https://us-south.ml.cloud.ibm.com/v3/wml_instances/997b1474-00d2-4g05-ac02-287ebfc603b5/deployments/997b1474-00d2-4g05-ac02-287ebfc603b5'}}]}
>>> response = client.service_providers.list_assets(
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        service_provider_id='997b1474-00d2-4g05-ac02-287ebfc603b5'
        deployment_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        deployment_space_id='6574djd4-00d2-4g05-ac02-287ebfc603b5'
     )
get_deployment_asset(data_mart_id: str, service_provider_id: str, deployment_id: str, deployment_space_id: Optional[str] = None) Response[source]

Listing all deployments and assets for specific data_mart and service_provider.

Parameters
  • data_mart_id (str) – ID of the data_mart (required)

  • service_provider_id (str) – ID of the service_provider (required)

  • deployment_id (str) – ID of the deployment (required), when used, only specific deployment is returned

  • deployment_space_id (str) – Reference to V2 Space ID (required)

Returns

Response

A way you may use me:

>>> response = client.service_providers.list_assets(
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        service_provider_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        deployment_space_id='6574djd4-00d2-4g05-ac02-287ebfc603b5'
     )
>>> print(response.result)
 {'entity': {'asset': {'asset_id': '997b1474-00d2-4g05-ac02-287ebfc603b5',
                                     'asset_type': 'model',
                                     'created_at': '2020-01-13T09:15:26.586Z',
                                     'name': 'AIOS Spark Credit Risk model',
                                     'url': 'https://us-south.ml.cloud.ibm.com/v3/wml_instances/997b1474-00d2-4g05-ac02-287ebfc603b5/published_models/997b1474-00d2-4g05-ac02-287ebfc603b5'},
                           'asset_properties': {'asset_revision': '997b1474-00d2-4g05-ac02-287ebfc603b5',
                                                'input_data_schema': {'fields': [{'metadata': {},
                                                                                  'name': 'CheckingStatus',
                                                                                  'nullable': True,
                                                                                  'type': 'string'},
                                                                                 ...
                                                'label_column': 'Risk',
                                                'model_type': 'mllib-2.3',
                                                'runtime_environment': 'spark-2.3',
                                                'training_data_schema': {'fields': [{'metadata': {},
                                                                                     'name': 'CheckingStatus',
                                                                                     'nullable': True,
                                                                                     'type': 'string'},
                                                                                    ...
                           'description': 'Description of deployment',
                           'name': 'AIOS Spark Credit Risk deployment',
                           'scoring_endpoint': {'url': 'https://us-south.ml.cloud.ibm.com/v3/wml_instances/997b1474-00d2-4g05-ac02-287ebfc603b5/deployments/997b1474-00d2-4g05-ac02-287ebfc603b5/online'},
                           'type': 'online'},
                'metadata': {'created_at': '2020-01-13T09:15:26.607Z',
                             'guid': '997b1474-00d2-4g05-ac02-287ebfc603b5',
                             'modified_at': '2020-01-13T09:15:26.848Z',
                             'url': 'https://us-south.ml.cloud.ibm.com/v3/wml_instances/997b1474-00d2-4g05-ac02-287ebfc603b5/deployments/997b1474-00d2-4g05-ac02-287ebfc603b5'}}
>>> response = client.service_providers.get_deployment_asset(
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        service_provider_id='997b1474-00d2-4g05-ac02-287ebfc603b5'
        deployment_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        deployment_space_id='6574djd4-00d2-4g05-ac02-287ebfc603b5'
     )
get(service_provider_id: str, **kwargs) DetailedResponse[source]

Get a specific service provider.

Get the assosiated Machine Learning service provider details.

Parameters
  • service_provider_id (str) – ID of the ML service provider.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with ServiceProviderResponse result

list(*, show_deleted: Optional[bool] = None, service_type: Optional[str] = None, instance_id: Optional[str] = None, operational_space_id: Optional[str] = None, deployment_space_id: Optional[str] = None, **kwargs) DetailedResponse[source]

List service providers.

List assosiated Machine Learning service instances.

Parameters
  • show_deleted (bool) – (optional) show also resources pending delete.

  • service_type (str) – (optional) Type of service.

  • instance_id (str) – (optional) comma-separeted list of IDs.

  • operational_space_id (str) – (optional) comma-separeted list of IDs.

  • deployment_space_id (str) – (optional) comma-separeted list of IDs.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with ServiceProviderResponseCollection result

update(service_provider_id: str, patch_document: List[PatchDocument], **kwargs) DetailedResponse[source]

Update a service provider.

Update existing service provider.

Parameters
  • service_provider_id (str) – ID of the ML service provider.

  • patch_document (List[PatchDocument]) –

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with ServiceProviderResponse result

APIClient.subscriptions

class Subscriptions(ai_client: WatsonOpenScaleV2Adapter)[source]

Bases: Subscriptions

Manages Subscription instance.

show(limit: Optional[int] = 10, data_mart_id: Optional[str] = None, service_provider_id: Optional[str] = None, asset_asset_id: Optional[str] = None, deployment_deployment_id: Optional[str] = None, deployment_deployment_type: Optional[str] = None, integration_reference_integrated_system_id: Optional[str] = None, integration_reference_external_id: Optional[str] = None, risk_evaluation_status_state: Optional[str] = None, service_provider_operational_space_id: Optional[str] = None, pre_production_reference_id: Optional[str] = None, **kwargs) None[source]

Show service providers. By default 10 records will be shown.

Parameters
  • limit (int) – maximal number of fetched rows. By default set to 10. (optional)

  • data_mart_id (str) – (optional) comma-separeted list of IDs.

  • service_provider_id (str) – (optional) comma-separeted list of IDs.

  • asset_asset_id (str) – (optional) comma-separeted list of IDs.

  • deployment_deployment_id (str) – (optional) comma-separeted list of IDs.

  • deployment_deployment_type (str) – (optional) comma-separeted list of types.

  • integration_reference_integrated_system_id (str) – (optional) comma-separeted list of IDs.

  • integration_reference_external_id (str) – (optional) comma-separeted list of IDs.

  • risk_evaluation_status_state (str) – (optional) comma-separeted list of states.

  • service_provider_operational_space_id (str) – (optional) comma-separeted list of operational space ids (property of service provider object).

  • pre_production_reference_id (str) – (optional) comma-separeted list of IDs.

  • headers (dict) – A dict containing the request headers

A way you might use me is:

>>> client.subscriptions.show()
>>> client.subscriptions.show(limit=20)
>>> client.subscriptions.show(limit=None)
add(data_mart_id: str, service_provider_id: str, asset: Asset, deployment: AssetDeploymentRequest, asset_properties: AssetPropertiesRequest = None, risk_evaluation_status: RiskEvaluationStatus = None, analytics_engine: AnalyticsEngine = None, data_sources: List[DataSource] = None, training_data_stats: dict = None, background_mode: bool = True, **kwargs) Optional[Union[DetailedResponse, dict]][source]

Add a subscription to the model deployment.

Parameters
  • data_mart_id (str) – ID of the data_mart (required)

  • service_provider_id (str) – ID of the service_provider (required)

  • asset (Asset) – an Asset object with asset’s information (required)

  • deployment (AssetDeploymentRequest) – an AssetDeploymentRequest object with deployment’s information (required)

  • asset_properties (AssetPropertiesRequest) – (optional) Additional asset properties (subject of discovery if not provided when creating the subscription).

  • risk_evaluation_status (RiskEvaluationStatus) – (optional)

  • analytics_engine (AnalyticsEngine) – (optional)

  • data_sources (List[DataSource]) – (optional)

  • training_data_stats – Training statistic json generated using training stats notebook (https://github.com/IBM-Watson/aios-data-distribution/blob/master/training_statistics_notebook.ipynb)

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with SubscriptionResponse result

A way you may use me:

>>> from ibm_watson_openscale import *
>>> added_subscription_info = client.subscriptions.add(
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        service_provider_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        asset=Asset(...),
        deployment=AssetDeploymentRequest(...),
        asset_properties=AssetPropertiesRequest(...),
     )
delete(subscription_id: str, force: bool = None, background_mode: bool = True) Optional[Union[DetailedResponse, dict]][source]

Delete subscription.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • force (bool) – (optional) force hard delete.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

A way you may use me:

>>> client.subscriptions.delete(
        background_mode=False,
        subscription_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        force=True
     )
create_feedback_table(subscription_id: str, **kwargs) DetailedResponse[source]

Create a table for feedback dataset type.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataSetResponse result

create_subscription_using_training_data(subscription_name, datamart_id, service_provider_id, model_info, sample_csv, spark_credentials, data_warehouse_connection, payload_table, feedback_table, scored_training_data_table, managed_by)[source]

Create batch subscription using model_info.

Parameters
  • subscription_name (str) – Name of this subscription.

  • datamart_id (str) – Datamart id in which we want to to create this subscription.

  • service_provider_id (str) – Service Provider id.

  • model_info (dict) –

    Information about the model which needs the subscription. Format for model_info model_info = {

    ”model_type”: “binary”, “label_column”: “Risk”, “prediction”: “predicted_label”, “probability”: “probability”, “feature_columns”: [list of categorical columns]/None, “categorical_columns”: [list of categorical columns]/None, “scoring”: {

    ”url”: “url”:”scoring url”, # This is required if explainability needs to be enabled, “token”: “token for scoring”, # This is mandatory for Azure ML studio Model

    }

    }

  • sample_csv (csv) – Sample csv file

  • spark_credentials (dict) –

    Dictionary containing spark connection information. Format for spark_credentials spark_credentials = {

    ”connection”: {

    “endpoint”: <SPARK_ENDPOINT>, “location_type”: <LOCATION_TYPE>, “display_name”: <DISPLAY_NAME>, “instance_id”: <INSTANCE_ID>, “volume”: <VOLUME>

    }, “credentials”: {

    ”username”: <USERNAME>, “apikey”: <APIKEY>

    }

    }

  • data_warehouse_connection (dict) –

    Dictionary containing data warehouse (DB connection) information. Format for the DB connection dataware_house_connection = {

    ”type”: “jdbc”, “connection”: {

    ”jdbc_driver”: “com.ibm.db2.jcc.DB2Driver”, “use_ssl”: False, “certificate”: None, “jdbc_url”: “jdbc:db2://<HOST>:50000/SAMPLE”

    }, “credentials”: {

    ”username”: “<USERNAME>”,

    ”password”: “<PASSWORD>”

    }

    }

  • payload_table (dict) –

    Dictionary containing payload table connection information. Format for the payload table payload_table = {

    ”data”: {

    “auto_create”: True, “database”: “SAMPLE”, “schema”: “KP”, “table”: “PAYLOAD_TABLE”

    }, “parameters”:{

    ”partition_column”: “WOS_PARTITION_COLUMN”, “num_partitions”: 12

    }

    }

  • feedback_table (dict) – Dictionary containing feedback table connection information.

  • scored_training_data_table (dict) –

    Dictionary scored trainin data table. Format for scored_training_data_table scored_training_data_table = {

    ”data”: {

    “auto_create”: False, “database”: “SAMPLE”, “schema”: “KP”, “table”: “SCORED_TRAINING_DATA_TABLE”

    }, “parameters”:{

    ”partition_column”: “WOS_PARTITION_COLUMN”, “num_partitions”: 12

    }

    }

  • managed_by (str) – To identify whether the subscription is online or batch. It should be either system for online subscription or self for batch subscripion.

create_subscription(subscription_name: str, datamart_id, service_provider_id, configuration_archive, spark_credentials, data_warehouse_connection, payload_table: dict = {}, feedback_table: dict = {}, model_info: dict = {}, **kwargs)[source]

Create batch subscription

Parameters
  • subscription_name (str) – Name of the subscription.

  • datamart_id (str) – Datamart id in which we want to to create this subscription.

  • service_provider_id (str) – Service Provider id.

  • configuration_archive (str) – Path to the configuration archive file.

  • spark_credentials (dict) –

    Dictionary containing spark connection information. Format for Remote Spark on hadoop spark_credentials = {

    ”connection”:{

    “endpoint”: “<SPARK_ENDPOINT>”, “location_type”: “custom”

    }, “credentials”: {

    ”username”: “<USERNAME>”, “password”: “<PASSWORD>”

    }, “spark_settings”: {

    ”max_num_executors”: <MAX_EXECUTOR_COUNT>, “min_num_executors”: <MIN_EXECUTOR_COUNT>, “executor_cores”: <EXECUTOR_CORE>, “executor_memory”: <EXECUTOR_MEMORY>, “driver_cores”: <NUM_OF_DRIVER_CORES>, “driver_memory”: <DRIVER_MEMORY>

    }

    } Format for IAE Spark spark_credentials = { “connection”: {

    ”display_name”: “<IAE_INSTANCE_DISPLAYNAME>”, “endpoint”: “<IAE_JOB_ENDPOINT>”, “location_type”: “cpd_iae”, “volume”: “<VOLUME_NAME>”

    }, “credentials”: {

    ”username”: “<USERNAME>”, “apikey”: “<APIKEY>”

    }, “spark_setting”: {

    #Look at remote spark settings

    }

} :param dict data_warehouse_connection: Dictionary containing data warehouse (DB connection) information.

Format for the DB connection dataware_house_connection = {

“type”: “jdbc”, “connection”: {

“jdbc_driver”: “com.ibm.db2.jcc.DB2Driver”, “use_ssl”: False, “certificate”: None, “jdbc_url”: “jdbc:db2://<HOST>:50000/SAMPLE”

}, “credentials”: {

“username”: “<USERNAME>”,

“password”: “<PASSWORD>”

}

}

Parameters
  • payload_table (dict) –

    Dictionary containing payload table connection information. Format for the payload table payload_table = {

    ”data”: {

    “auto_create”: True, “database”: “SAMPLE”, “schema”: “KP”, “table”: “PAYLOAD_GERMAN_CREDIT_DATA_NEW”

    }, “parameters”:{

    ”partition_column”: “WOS_PARTITION_COLUMN”, “num_partitions”: 12

    }

    }

  • feedback_table (dict) – Dictionary containing feedback table connection information. Format for the feedback_table is same as payload table

  • model_info (dict) –

    Information about the model which needs the subscription. Format for model_info model_info = {

    ”model_type”: “binary”, “label_column”: “Risk”, “prediction”: “predicted_label”, “probability”: “probability”, “feature_columns”: [list of categorical columns]/None, “categorical_columns”: [list of categorical columns]/None, “scoring”: {

    ”url”: “url”:”scoring url”, # This is required if explainability needs to be enabled, “token”: “token for scoring”, # This is mandatory for Azure ML studio Model

    }

    }

Returns

subscription id

Return type

str

get(subscription_id: str, **kwargs) DetailedResponse[source]

Get a specific subscription.

Get a specific subscription.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with SubscriptionResponse result

list(*, data_mart_id: Optional[str] = None, service_provider_id: Optional[str] = None, asset_asset_id: Optional[str] = None, deployment_deployment_id: Optional[str] = None, deployment_deployment_type: Optional[str] = None, integration_reference_integrated_system_id: Optional[str] = None, integration_reference_external_id: Optional[str] = None, risk_evaluation_status_state: Optional[str] = None, service_provider_operational_space_id: Optional[str] = None, pre_production_reference_id: Optional[str] = None, **kwargs) DetailedResponse[source]

List subscriptions.

List subscriptions.

Parameters
  • data_mart_id (str) – (optional) comma-separeted list of IDs.

  • service_provider_id (str) – (optional) comma-separeted list of IDs.

  • asset_asset_id (str) – (optional) comma-separeted list of IDs.

  • deployment_deployment_id (str) – (optional) comma-separeted list of IDs.

  • deployment_deployment_type (str) – (optional) comma-separeted list of types.

  • integration_reference_integrated_system_id (str) – (optional) comma-separeted list of IDs.

  • integration_reference_external_id (str) – (optional) comma-separeted list of IDs.

  • risk_evaluation_status_state (str) – (optional) comma-separeted list of states.

  • service_provider_operational_space_id (str) – (optional) comma-separeted list of operational space ids (property of service provider object).

  • pre_production_reference_id (str) – (optional) comma-separeted list of IDs.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with SubscriptionResponseCollection result

schemas(subscription_id: str, *, input_data: Optional[List[ScoreData]] = None, training_data_reference: Optional[InputDataReference] = None, **kwargs) DetailedResponse[source]

Derive model schemas from the training data.

Derive model schemas from the training data. Only “structured” input data type is supported. If the input_data_type field in the subscription (subscription -> entity -> asset -> input_data_type) is not “structured”, an error will be returned.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • input_data (List[ScoreData]) – (optional) Array of score data object. If multiple score data objects are included, the “fields” array (if any) for score purposes will always be taken from the first score data object.

  • training_data_reference (InputDataReference) – (optional) InputDataReference is the same as TrainingDataReference except that neither location nor connection is required. This is needed for the Schemas API and to avoid updating existing APIs.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with SchemaInferenceResponse result

score(subscription_id: str, values: List[str], *, fields: Optional[List[str]] = None, **kwargs) DetailedResponse[source]

Computes the bias mitigation/remediation for the specified model.

Computes the bias mitigation/remediation for the specified model. The fairness monitoring debias request payload details must be valid.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • values (List[str]) – The values associated to the fields.

  • fields (List[str]) – (optional) The fields to process debias scoring.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with FairnessMonitoringRemediation result

tables(subscription_id: str, dataset_type: str, unknown_base_type: object, **kwargs) DetailedResponse[source]

Create a table for specified data set type.

Current supported dataset_type is feedback. The body of request should be json object (an empty object {} is fine).

Parameters
  • subscription_id (str) – Unique subscription ID.

  • dataset_type (str) – data set type of subscription.

  • unknown_base_type (UNKNOWN_BASE_TYPE) –

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataSetResponse result

update(subscription_id: str, patch_document: List[PatchDocument], **kwargs) DetailedResponse[source]

Update a subscription.

Update existing asset (from ML service instance) subscription.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • patch_document (List[PatchDocument]) –

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with SubscriptionResponse result

APIClient.data_sets

class DataSets(ai_client: WatsonOpenScaleV2Adapter)[source]

Bases: DataSets

Manages Data Sets.

show(limit: int = 10, target_target_id: Optional[str] = None, target_target_type: Optional[str] = None, type: Optional[str] = None, managed_by: Optional[str] = None, **kwargs) None[source]

Show data sets. By default 10 records will be shown.

Parameters
  • limit (int) – maximal number of fetched rows. By default set to 10. (optional)

  • target_target_id (str) – (optional) ID of the data set target (e.g. subscription ID, business application ID).

  • target_target_type (str) – (optional) type of the target.

  • type (str) – (optional) type of the data set.

  • managed_by (str) – (optional) ID of the managing entity (e.g. business application ID).

  • headers (dict) – A dict containing the request headers

Returns

None

A way you might use me is:

>>>   client.data_sets.show()
>>>   client.data_sets.show(limit=20)
>>>   client.data_sets.show(limit=None)
add(data_mart_id: str, name: str, type: str, target: Target, data_schema: SparkStruct, description: str = None, schema_update_mode: str = None, location: LocationTableName = None, managed_by: str = None, background_mode: bool = True) Optional[Union[DetailedResponse, dict]][source]

Create Data Set.

Parameters
  • data_mart_id (str) –

  • name (str) –

  • type (str) –

  • target (Target) –

  • data_schema (SparkStruct) –

  • description (str) – (optional)

  • schema_update_mode (str) – (optional)

  • location (LocationTableName) – (optional)

  • managed_by (str) – (optional)

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataSetResponse result

A way you might use me is:

>>> from ibm_watson_openscale import *
>>> target = Target(
         target_id='subscription_id',
          target_type=TargetTypes.SUBSCRIPTION
       )
>>> data_schema = SparkStruct(
          type='struct',
          fields=[
              SparkStructField(
                  name='CheckingStatus',
                  type='string',
                  nullable=True,
                  metadata={'columnInfo': {'columnLength': 64},
                            'measure': 'discrete',
                            'modeling_role': 'feature'}
              ),
              SparkStructField(
                  name='LoanDuration',
                  type='integer',
                  nullable=True,
                  metadata={'modeling_role': 'feature'}
              ),
              SparkStructField(
                  name='asset_revision',
                  type='string',
                  nullable=True,
                  metadata={}
              )
          ]
       )
>>> custom_dataset_info = client.data_sets.add(
          target=target,
          name='custom dataset',
          type='custom',
          data_schema=data_schema,
          data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5'
       )
delete(data_set_id: str, background_mode: bool = True, force: bool = False) Optional[Union[DetailedResponse, dict]][source]

Delete Data Set.

Parameters
  • data_set_id (str) – ID of the data set.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

A way you may use me:

>>> client.data_sets.delete(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5')
store_records(data_set_id: str, request_body: Union[str, BufferedReader, List[PayloadRecord], List[List], List[Dict]], header: bool = None, skip: int = None, limit: int = None, delimiter: str = None, on_error: str = None, csv_max_line_length: float = None, background_mode: bool = True) Optional[Union[DetailedResponse, dict]][source]

Store records to specific data set.

Parameters
  • data_set_id (str) – ID of the data set.

  • scoring_payload_request (list[ScoringPayloadRequest]) –

  • header (bool) – (optional) if not provided service will attempt to automatically detect header in the first line.

  • skip (int) – (optional) skip number of rows from input.

  • limit (int) – (optional) limit for number of processed input rows.

  • delimiter (str) – (optional) delimiter character for data provided as csv.

  • on_error (str) – (optional) expected behaviour on error.

  • csv_max_line_length (float) – (optional) maximum length of single line in bytes (default 10MB).

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with Status result

A way you might use me is:

>>> from ibm_watson_openscale import *
>>> store_record_info = client.data_sets.store_records(
      request_body=[
                {
                  "GENDER": "M",
                  "PRODUCT_LINE": "Golf Equipment",
                  "AGE": 25,
                  "MARITAL_STATUS": "Unspecified",
                  "PROFESSION": "Sales"
                },
                {
                  "GENDER": "M",
                  "PRODUCT_LINE": "Sport shoes",
                  "AGE": 28,
                  "MARITAL_STATUS": "Married",
                  "PROFESSION": "Sales"
                },
                {
                  "GENDER": "F",
                  "PRODUCT_LINE": "Sport shoes",
                  "AGE": 25,
                  "MARITAL_STATUS": "Single",
                  "PROFESSION": "Software Developer"
                }
          ],
      data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
  )
>>> from ibm_watson_openscale.supporting_classes.payload_record import PayloadRecord
>>> store_record_info = client.data_sets.store_records(
      request_body=[PayloadRecord(
           scoring_id='42e62c3ae2244f0d851009dec4754d74',
           request={
              "fields": ["CheckingStatus", "LoanDuration", "CreditHistory", "LoanPurpose",
                  "LoanAmount", "ExistingSavings", "EmploymentDuration", "InstallmentPercent", "Sex",
                  "OthersOnLoan", "CurrentResidenceDuration", "OwnsProperty", "Age", "InstallmentPlans",
                  "Housing", "ExistingCreditsCount", "Job", "Dependents", "Telephone", "ForeignWorker"],
              "values": [["less_0", 4, "all_credits_paid_back", "car_new", 250, "less_100", "less_1", 2,
                  "male", "none", 1, "real_estate", 26, "stores", "rent", 1, "unskilled", 1,
                  "none", "yes"]]
              },
           response={
              "fields": ["CheckingStatus", "LoanDuration", "CreditHistory", "LoanPurpose", "LoanAmount",
                  "ExistingSavings", "EmploymentDuration", "InstallmentPercent", "Sex", "OthersOnLoan",
                  "CurrentResidenceDuration", "OwnsProperty", "Age", "InstallmentPlans", "Housing",
                  "ExistingCreditsCount", "Job", "Dependents", "Telephone", "ForeignWorker",
                  "CheckingStatus_IX", "CreditHistory_IX", "EmploymentDuration_IX", "ExistingSavings_IX",
                  "ForeignWorker_IX", "Housing_IX", "InstallmentPlans_IX", "Job_IX", "LoanPurpose_IX",
                  "OthersOnLoan_IX", "OwnsProperty_IX", "Sex_IX", "Telephone_IX", "features", "rawPrediction",
                  "probability", "prediction", "predictedLabel"],
              "values": [["less_0", 4, "all_credits_paid_back", "car_new", 250, "less_100", "less_1", 2,
                  "male", "none", 1, "real_estate", 26, "stores", "rent", 1, "unskilled", 1, "none", "yes",
                  1.0, 3.0, 3.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 2.0, 0.0, 0.0, [1.0, 3.0, 0.0, 0.0, 3.0,
                  0.0, 0.0, 2.0, 1.0, 1.0, 1.0, 0.0, 0.0, 4.0, 250.0, 2.0, 1.0, 4.0, 26.0, 1.0, 1.0],
                  [19.600662549552556, 0.39933745044744245], [0.9800331274776278, 0.01996687252237212],
                  0.0, "No Risk"]]
              },
           response_time=460
       )],
      data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
  )
>>> csv_buffer_reader = io.open('path_to_csv', mode="rb")
>>> store_record_info = client.data_sets.store_records(
      request_body=csv_buffer_reader,
      delimiter=',',
      header=True,
      limit=100,
      data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
      csv_max_line_length = 8196
  )
get_update_status(data_set_id: str, request_id: str) DetailedResponse[source]

Get status of the specific request.

Parameters
  • data_set_id (str) – ID of the data set.

  • request_id (str) – ID of the request.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with Status result

A way you might use me is:

>>> update_status = client.data_sets.get_update_status(
      data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
      request_id='7843-00d35462-346-ac0672-7357'
   )
get_list_of_records(data_set_id: str, limit: int = 100, start: datetime = None, end: datetime = None, offset: int = None, annotations: List[str] = None, filter: str = None, include_total_count: bool = None, format: str = None, output_type: str = None, include_internal_columns=False, return_payload_raw_data=False) Union[DetailedResponse, DataFrame][source]

List data set records.

Parameters
  • data_set_id (str) – ID of the data set.

  • limit (int) – By default it will return 100 records. If the value is greater than 1000 than it will be truncated.

  • start (datetime) – (optional) return records with timestamp greater than or equal to start parameter. Date string should be in the UTC ISO 8601 format. Ex: 2021-06-10T09:43:53.309Z

  • end (datetime) – (optional) return records with timestamp lower than end parameter. Date string should be in the UTC ISO 8601 format. Ex: 2021-06-10T09:43:53.309Z

  • offset (int) – (optional) offset of returned records.

  • annotations (list[str]) – (optional) return record annotations with given names.

  • filter (str) – (optional) return records for which transaction ids in associated data set the condition is met, format: {data_set_id}.{field_name}:{op}:{value}.

  • include_total_count (bool) – (optional) If total_count should be included. It can have performance impact if total_count is calculated.

  • filter – (optional) return records for which transaction ids in associated data set the condition is met, format: {data_set_id}.{field_name}:{op}:{value}.

  • format (str) – (optional) What JSON format to use on output.

  • output_type (str) – (optional) type of the response data to be present, default is ‘dict’, available option is ‘pandas’

  • include_internal_columns (bool) – (optional) Flag to retrieve internal columns

  • return_payload_raw_data (bool) – (optional) Flag to retrieve only the raw data which was used for scoring. Applicable to only Payload Logging data and format is ‘pandas’

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataRecordsResponseCollection result

A way you might use me is:

>>> records = client.data_sets.get_list_of_records(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5')
>>> records = client.data_sets.get_list_of_records(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
                                                   format=RecordsFormatTypes.DICT
   )
>>> records = client.data_sets.get_list_of_records(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
                                                   format=RecordsFormatTypes.LIST
   )
>>> records = client.data_sets.get_list_of_records(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
                                                   output_type=ResponseTypes.PYTHON
   )
>>> records = client.data_sets.get_list_of_records(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
                                                   output_type=ResponseTypes.PANDAS
   )
show_records(data_set_id: Optional[str] = None, limit: int = 10) None[source]

Show data set records. By default 10 records will be shown.

Parameters
  • data_set_id (str) – ID of the data set.

  • limit (int) – Maximal number of fetched rows. By default set to 10. (optional)

Returns

None

A way you might use me is:

>>> client.data_sets.show_records(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5')
print_records_schema(data_set_id: Optional[str] = None) None[source]

Show data set records. By default 10 records will be shown.

Parameters

data_set_id (str) – ID of the data set.

Returns

None

A way you might use me is:

>>> client.data_sets.print_records_schema(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5')
get_records_count(data_set_id: Optional[str] = None) int[source]

Count data set records.

Parameters

data_set_id – ID of the data set.

Returns

int

A way you might use me is:

>>> number_of_records = client.data_sets.get_records_count(data_set_id='997b1474-00d2-4g05-ac02-287ebfc603b5')
get(data_set_id: str, **kwargs) DetailedResponse[source]

Get data set with the given id.

Parameters
  • data_set_id (str) – ID of the data set.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataSetResponse result

list(*, target_target_id: Optional[str] = None, target_target_type: Optional[str] = None, type: Optional[str] = None, managed_by: Optional[str] = None, **kwargs) DetailedResponse[source]

List all data sets specified by the parameters.

Parameters
  • target_target_id (str) – (optional) ID of the data set target (e.g. subscription ID, business application ID).

  • target_target_type (str) – (optional) type of the target.

  • type (str) – (optional) type of the data set.

  • managed_by (str) – (optional) ID of the managing entity (e.g. business application ID).

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataSetResponseCollection result

update(data_set_id: str, patch_document: List[PatchDocument], **kwargs) DetailedResponse[source]

Update a data set.

Update the data set.

Parameters
  • data_set_id (str) – ID of the data set.

  • patch_document (List[PatchDocument]) –

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataSetResponse result

APIClient.monitor_instances

class MonitorInstances(ai_client: WatsonOpenScaleV2Adapter)[source]

Bases: Instances

Manages Monitor Instances.

run(monitor_instance_id: str, triggered_by: Optional[str] = None, parameters=None, business_metric_context=None, background_mode: bool = True) Any[source]

Trigger monitoring run. :param str monitor_instance_id: Unique monitor instance ID. :param str triggered_by: (optional) An identifier representing the source

that triggered the run request (optional). One of: event, scheduler, user, webhook.

Parameters
  • parameters (MonitorInstanceParameters) – (optional) Monitoring parameters consistent with the parameters_schema from the monitor definition.

  • business_metric_context (MonitoringRunBusinessMetricContext) – (optional) Properties defining the business metric context in the triggered run of AI metric calculation.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitoringRun result

A way you may use me:

>>> monitor_instance_run_info = client.monitor_instances.run(
        background_mode=False,
        monitor_instance_id='997b1474-00d2-4g05-ac02-287ebfc603b5'
     )
list(data_mart_id: str = None, monitor_definition_id: str = None, target_target_id: str = None, target_target_type: str = None) DetailedResponse[source]

List monitor instances.

Parameters
  • data_mart_id (str) – (optional) comma-separeted list of IDs.

  • monitor_definition_id (str) – (optional) comma-separeted list of IDs.

  • target_target_id (str) – (optional) comma-separeted list of IDs.

  • target_target_type (str) – (optional) comma-separeted list of types.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorInstanceCollection result

A way you may use me:

>>> monitor_instances_info = client.monitor_instances.list(
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
     )
show(limit: int = 10, data_mart_id: Optional[str] = None, monitor_definition_id: Optional[str] = None, target_target_id: Optional[str] = None, target_target_type: Optional[str] = None) None[source]

Show monitor instances. By default 10 records will be shown.

Parameters
  • limit (int) – Maximal number of fetched rows. By default set to 10. (optional)

  • data_mart_id (str) – (optional) comma-separeted list of IDs.

  • monitor_definition_id (str) – (optional) comma-separeted list of IDs.

  • target_target_id (str) – (optional) comma-separeted list of IDs.

  • target_target_type (str) – (optional) comma-separeted list of types.

Returns

None

A way you might use me is:

>>> client.monitor_instances.show()
>>> client.monitor_instances.show(limit=20)
>>> client.monitor_instances.show(20)
show_metrics(monitor_instance_id: str, limit: int = 10)[source]

Show metrics for monitor instance.

Parameters
  • monitor_instance_id (str) – ID of the monitor instance.

  • limit (int) – maximal number of fetched rows. By default set to 10. (optional)

Returns

None

A way you might use me is:

>>> client.monitor_instances.show_metrics(monitor_instance_id='997b1474-00d2-4g05-ac02-287ebfc603b5')
create(monitor_definition_id: str, target: Target, data_mart_id: str = None, parameters: MonitorInstanceParameters = None, thresholds: List[MetricThresholdOverride] = None, schedule: MonitorInstanceSchedule = None, managed_by: str = None, training_data_stats: dict = None, background_mode: bool = True, **kwargs) Optional[Union[DetailedResponse, dict]][source]

Create monitor instance.

Parameters
  • data_mart_id (str) –

  • monitor_definition_id (str) –

  • target (Target) –

  • parameters (MonitorInstanceParameters) – (optional) Monitoring parameters consistent with the parameters_schema from the monitor definition.

  • thresholds (list[MetricThresholdOverride]) – (optional)

  • schedule (MonitorInstanceSchedule) – (optional) The schedule used to control how frequently the target is monitored. The maximum frequency is once every 30 minutes. Defaults to once every hour if not specified.

  • managed_by (str) – (optional)

  • training_data_stats – Training statistic json generated using training stats notebook (https://github.com/IBM-Watson/aios-data-distribution/blob/master/training_statistics_notebook.ipynb)

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorInstanceResponse result

A way you might use me is:

>>> from ibm_watson_openscale import *
>>> target = Target(
        target_type=TargetTypes.SUBSCRIPTION,
        target_id='997b1474-00d2-4g05-ac02-287ebfc603b5'
     )
>>> parameters = MonitorInstanceParameters(
        min_feedback_data_size=50
     )
>>> thresholds = [
        MetricThresholdOverride(
            metric_id=client.monitor_definitions.MONITORS.QUALITY.METRIC.ACCURACY,
            type=MetricThresholdTypes.LOWER_LIMIT,
            value=0.7
        )
     ]
>>> monitor_instances_info = client.monitor_instances.create(
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        background_mode=False,
        monitor_definition_id=client.monitor_definitions.MONITORS.QUALITY.ID,
        target=target,
        parameters=parameters,
        thresholds=thresholds
     )
delete(monitor_instance_id: str, background_mode: bool = True, force: bool = False) Optional[Union[DetailedResponse, dict]][source]

Delete monitor instance.

Parameters
  • monitor_instance_id (str) – Unique monitor instance ID.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

A way you might use me is:

>>> ai_client_v2.monitor_instances.delete(
        background_mode=False,
        monitor_instance_id='997b1474-00d2-4g05-ac02-287ebfc603b5'
     )
get(monitor_instance_id: str) DetailedResponse[source]

Get monitor instance details.

Parameters

monitor_instance_id (str) – Unique monitor instance ID.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorInstanceResponse result

A way you might use me is:

>>> monitor_instance_info = client.monitor_instances.get(
        monitor_instance_id='997b1474-00d2-4g05-ac02-287ebfc603b5'
     )
update(monitor_instance_id: str, patch_document: List[PatchDocument], update_metadata_only: bool = None) DetailedResponse[source]

Update monitor instance.

Parameters
  • monitor_instance_id (str) – Unique monitor instance ID.

  • patch_document (List[PatchDocument]) –

  • update_metadata_only (bool) – (optional) Flag that allows to control if the underlaying actions related to the monitor reconfiguration should be triggered.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorInstanceResponse result

get_metrics_count(monitor_instance_id: str, start: datetime, end: datetime, interval: str = None, filter: str = None, group: str = None)[source]

Get the count of the metrics.

Parameters
  • monitor_instance_id (str) – Unique monitor instance ID.

  • start (datetime) – Calculations inclusive, internally floored to achieve full interval. If interval is vulnerable to time zone, the calculated value depends on a backend db engine: PostgreSQL respects time zone and DB2 use UTC time. Calculated value is returned in response.

  • end (datetime) – Calculations exclusive, internally ceiled to achieve full interval. If interval is vulnerable to time zone, the calculated value depends on a backend db engine: PostgreSQL respects time zone and DB2 use UTC time. Calculated value is returned in response.

  • agg (str) – Comma delimited function list constructed from metric name and function, e.g. agg=metric_name:count,:last that defines aggregations.

  • interval (str) – (optional) Time unit in which metrics are grouped and aggregated, interval by interval.

  • filter (str) – (optional) Filter expression can consist of any metric tag or a common column of string type followed by filter name and optionally a value, all delimited by colon. Supported filters are: in, eq, null and exists. Sample filters are: filter=region:in:[us,pl],segment:eq:sales or filter=region:null,segment:exists.

  • group (str) – (optional) Comma delimited list constructed from metric tags, e.g. group=region,segment to group metrics before aggregations.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataMartGetMonitorInstanceMetrics result

A way you might use me is:

>>> metrics_count = client.monitor_instances.get_metrics_count(
        monitor_instance_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        start=start_time,
        end=end_time,
     )
get_metrics(monitor_instance_id: str, start: datetime, end: datetime, interval: str = None, filter: str = None, group: str = None)[source]

Get all the generated metrics between start and end date for specific monitor instance id

Parameters
  • monitor_instance_id (str) – Unique monitor instance ID.

  • start (datetime) – Calculations inclusive, internally floored to achieve full interval. If interval is vulnerable to time zone, the calculated value depends on a backend db engine: PostgreSQL respects time zone and DB2 use UTC time. Calculated value is returned in response.

  • end (datetime) – Calculations exclusive, internally ceiled to achieve full interval. If interval is vulnerable to time zone, the calculated value depends on a backend db engine: PostgreSQL respects time zone and DB2 use UTC time. Calculated value is returned in response.

  • agg (str) – Comma delimited function list constructed from metric name and function, e.g. agg=metric_name:count,:last that defines aggregations.

  • interval (str) – (optional) Time unit in which metrics are grouped and aggregated, interval by interval.

  • filter (str) – (optional) Filter expression can consist of any metric tag or a common column of string type followed by filter name and optionally a value, all delimited by colon. Supported filters are: in, eq, null and exists. Sample filters are: filter=region:in:[us,pl],segment:eq:sales or filter=region:null,segment:exists.

  • group (str) – (optional) Comma delimited list constructed from metric tags, e.g. group=region,segment to group metrics before aggregations.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with DataMartGetMonitorInstanceMetrics result

A way you might use me is:

>>> metrics_count = client.monitor_instances.get_metrics_count(
        monitor_instance_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        start=start_time,
        end=end_time,
     )
upload_drift_model(model_path: str, data_mart_id: str, subscription_id: str, archive_name: str = 'user_drift.tar.gz', enable_data_drift: bool = True, enable_model_drift: bool = True) DetailedResponse[source]

Upload a Drift model to be able to compute Drift monitor.

Parameters
  • model_path (str) – (required) path to the drift model

  • data_mart_id (str) – (required) data_mart ID

  • subscription_id (str) – (required) subscription ID

  • archive_name (str) – (optional) Archive name to use while storing tarball in datamart

  • enable_data_drift (str) – (optional) If data drift is expected to be enabled for this subscription. If set to True, archive is verified to contain a valid data constraints json file.

  • enable_model_drift (str) – (optional) If model drift is expected to be enabled for this subscription. If set to True, archive is verified to contain a valid drift model pickle file.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

A way you might use me is:

>>> client.monitor_instances.upload_drift_model(
        model_path='drift_models/drift_detection_model.tar.gz',
        data_mart_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
        subscription_id='997b1474-00d2-4g05-ac02-287ebfc603b5',
     )
download_drift_model(monitor_instance_id: str) DetailedResponse[source]

Downloads the model.

Parameters

monitor_instance_id (str) – (required) The Drift monitor instance ID.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

A way you might use me is:

>>> client.monitor_instances.download_drift_model(
    monitor_instance_id="0a9a4b85-f2bb-46de-850b-f033d7d37d9a"
    )
download_drift_model_metadata(monitor_instance_id: str) DetailedResponse[source]

Downloads the model metadata.

Parameters

monitor_instance_id (str) – (required) The Drift monitor instance ID.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

A way you might use me is:

>>> client.monitor_instances.download_drift_model_metadata(
    monitor_instance_id="0a9a4b85-f2bb-46de-850b-f033d7d37d9a"
    )
list_runs(monitor_instance_id: str, start: Optional[str] = None, limit: Optional[int] = None)[source]

List monitoring runs.

List monitoring runs.

Parameters
  • monitor_instance_id (str) – Unique monitor instance ID.

  • start (str) – (optional) The page token indicating where to start paging from.

  • limit (int) – (optional) The limit of the number of items to return, for example limit=50. If not specified a default of 100 will be used.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitoringRunCollection result

get_run_details(monitor_instance_id: str, monitoring_run_id: str, **kwargs)[source]

Get monitoring run details. :param str monitor_instance_id: Unique monitor instance ID. :param str monitoring_run_id: Unique monitoring run ID. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse with MonitoringRun result

explanation_tasks(scoring_ids: List[str], input_rows: Optional[List[dict]] = None, explanation_types: Optional[List[str]] = None, subscription_id=None, **kwargs)[source]

Compute explanations.

Submit tasks for computing explanation of predictions.

Parameters
  • scoring_ids (List[str]) – IDs of the scoring transaction.

  • input_rows (List[dict]) – (optional) List of scoring transactions.

  • explanation_types (List[str]) – (optional) Types of explanations to generate.

  • subscription_id (str) – (optional) Unique subscription ID.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with PostExplanationTaskResponse result

get_explanation_tasks(explanation_task_id: str, subscription_id=None, **kwargs)[source]

Get explanation.

Get explanation for the given explanation task id.

Parameters
  • explanation_task_id (str) – ID of the explanation task.

  • subscription_id (str) – Unique subscription ID.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with GetExplanationTaskResponse result

get_all_explaination_tasks(offset=None, limit=None, subscription_id=None, scoring_id=None, status=None, **kwargs)[source]

List all explanations.

List of all the computed explanations.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • offset (int) – (optional) offset of the explanations to return.

  • limit (int) – (optional) Maximum number of explanations to return.

  • scoring_id (str) – (optional) ID of the scoring transaction.

  • status (str) – (optional) Status of the explanation task.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with GetExplanationTasksResponse result

get_measurement_details(monitor_instance_id: str, measurement_id: str, **kwargs)[source]

Get Measurement details. Get Measurement info for the given measurement and monitor instance id. :param str monitor_instance_id: ID of the monitor instance. :param str measurement_id: ID of the measurement. :param dict headers: A dict containing the request headers :return: A DetailedResponse containing the result, headers and HTTP status code. :rtype: DetailedResponse with MonitorMeasurementResponse result

add_measurements(monitor_instance_id: str, monitor_measurement_request: List[MonitorMeasurementRequest], **kwargs)[source]

Publish measurement data to OpenScale.

Publish measurement data to OpenScale for a specific monitor instance.

Parameters
  • monitor_instance_id (str) – Unique monitor instance ID.

  • monitor_measurement_request (List[MonitorMeasurementRequest]) –

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

upload_explainability_archive(subscription_id: str, archive: BinaryIO, **kwargs)[source]

Upload explainability archives.

API to upload explainability archives such as the Perturbations scoring response archive. The api can also be used to update the archive.

Parameters
  • subscription_id (str) – Unique subscription ID.

  • archive (BinaryIO) – explanation Archive

Return type

DetailedResponse

get_explainability_archive(subscription_id: str, **kwargs)[source]

Retrieves the Explainability archives.

API to retrieve the Explainability archives.

Parameters

subscription_id (str) – Unique subscription ID.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

enable_monitor_using_training_data(datamart_id, subscription_id, monitors_config, drifted_transaction_table={}, explain_queue_table={}, explain_results_table={})[source]

Enable configured monitors and learn stats online

Parameters
  • datamart_id (str) – Datamart id in which we want to to create this subscription.

  • subscription_id (str) – subscription id

  • monitors_config (dict) –

    configuration params for monitors Format for the monitors_config is as follows monitors_config = {

    ”fairness_configuration”: {

    “enabled”: True, “parameters”: { }, “thresholds”: [ ]

    }, “quality_configuration”: {

    ”enabled”: True, “parameters” : { }, “thresholds” : []

    }, “explainability_configuration”:{

    ”enabled”: True, “parameters” : {

    ”enable_online_learning”: True

    }

    }, “drift_configuration”: {

    ”enabled”: True, “parameters” : { “train_drift_model”: True }

    }

    }

  • drifted_transaction_table (dict) –

    Dictionary containing drifted transaction table connection information. Required if drift is to be configured Format for the drifted transaction table is as follows drifted_transaction_table = {

    ”data”: {

    “auto_create”: False, “database”: “SAMPLE”, “schema”: “KP”, “table”: “DRIFTED_TRANSACTION_TABLE”

    }, “parameters”:{

    ”partition_column”: “WOS_PARTITION_COLUMN”, “num_partitions”: 12

    }

    }

  • explain_queue_table (dict) – Dictionary containing explanation queue table connection information. Required if explanation is to be configured. Format for the explain_queue_table is same as drifted transaction table

  • explain_results_table (dict) – Dictionary containing explanation results table connection information. Required if explanation is to be configured. Format for the explain_results_table is same as drifted transaction table

Returns

list containing monitor instance ids

Return type

list

enable_monitors(datamart_id, service_provider_id, subscription_id, configuration_archive, drifted_transaction_table={}, explain_queue_table={}, explain_results_table={})[source]

Enable configured monitors using configuration archive file

Parameters
  • datamart_id (str) – Datamart id in which we want to to create this subscription.

  • service_provider_id (str) – Service Provider id.

  • configuration_archive (str) – Path to the configuration archive.

  • drifted_transaction_table (dict) –

    Dictionary containing drifted transaction table connection information. Required if drift is to be configured Format for the drifted transaction table is as follows

    drifted_transaction_table = {
    “data”: {

    “auto_create”: True, “database”: “SAMPLE”, “schema”: “KP”, “table”: “drifted_transactions_table_new”

    }

    }

  • explain_queue_table (dict) – Dictionary containing explanation queue table connection information. Required if explanation is to be configured. Format for the explain_queue_table is same as drifted transaction table

  • explain_results_table (dict) – Dictionary containing explanation results table connection information. Required if explanation is to be configured. Format for the explain_results_table is same as drifted transaction table

Returns

list containing monitor instance ids

Return type

list

APIClient.monitor_definitions

class MonitorDefinitions(ai_client: WatsonOpenScaleV2Adapter)[source]

Bases: Monitors

Manages Monitor Definitions.

add(name: str, metrics: List[MonitorMetricRequest], tags: List[MonitorTagRequest], description: str = None, applies_to: ApplicabilitySelection = None, parameters_schema: object = None, managed_by: str = None, schedule: MonitorInstanceSchedule = None, monitor_runtime: MonitorRuntime = None, background_mode: bool = True) Optional[Union[DetailedResponse, dict]][source]

Add custom monitor.

Parameters
  • name (str) – Monitor UI label (must be unique).

  • metrics (List[MonitorMetricRequest]) – A list of metric definition.

  • tags (List[MonitorTagRequest]) – Available tags.

  • description (str) – (optional) Long monitoring description presented in monitoring catalog.

  • applies_to (ApplicabilitySelection) – (optional)

  • parameters_schema (object) – (optional) JSON schema that will be used to validate monitoring parameters when enabled.

  • managed_by (str) – (optional)

  • schedule (MonitorInstanceSchedule) – (optional) The schedule used to control how frequently the target is monitored. The maximum frequency is once every 30 minutes. Defaults to once every hour if not specified.

  • monitor_runtime (MonitorRuntime) – (optional) Field to specify if scheduler should be created or not.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorDisplayForm result

A way you may use me:

>>>  from ibm_watson_openscale import *
>>>  metrics = [
       MonitorMetricRequest(
           name='sensitivity',
           thresholds=[MetricThreshold(
               type=MetricThresholdTypes.LOWER_LIMIT,
               default=0.8
           )]
       ),
       MonitorMetricRequest(
           name='specificity',
           thresholds=[MetricThreshold(
               type=MetricThresholdTypes.LOWER_LIMIT,
               default=0.75
           )]
       ),
    ]
>>>  tags = [
       MonitorTagRequest(
           name='region',
           description='customer geographical region'
       )
    ]
>>>  my_monitor = client.monitor_definitions.add(
           name='my model performance',
           metrics=metrics,
           tags=tags,
           background_mode=False)
delete(monitor_definition_id: str, background_mode: bool = True, force: bool = False) Optional[Union[DetailedResponse, dict]][source]

Delete custom monitor.

Parameters
  • monitor_definition_id (str) – Unique monitor definition ID.

  • background_mode (bool) – if set to True, run will be in asynchronous mode, if set to False it will wait for result (optional)

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

A way you may use me:

>>>  client.monitor_definitions.delete(monitor_definition_id='997b1474-00d2-4g05-ac02-287ebfc603b5')
update(monitor_definition_id: str, name: str, metrics: List[MonitorMetricRequest], tags: List[MonitorTagRequest], description: str = None, applies_to: ApplicabilitySelection = None, parameters_schema: object = None, managed_by: str = None, schedule: MonitorInstanceSchedule = None) DetailedResponse[source]

Edit custom monitor.

Update monitor.

Parameters
  • monitor_definition_id (str) – Unique monitor definition ID.

  • name (str) – Monitor UI label (must be unique).

  • metrics (List[MonitorMetricRequest]) – A list of metric definition.

  • tags (List[MonitorTagRequest]) – Available tags.

  • description (str) – (optional) Long monitoring description presented in monitoring catalog.

  • applies_to (ApplicabilitySelection) – (optional)

  • parameters_schema (object) – (optional) JSON schema that will be used to validate monitoring parameters when enabled.

  • managed_by (str) – (optional)

  • schedule (MonitorInstanceSchedule) – (optional) The schedule used to control how frequently the target is monitored. The maximum frequency is once every 30 minutes. Defaults to once every hour if not specified.

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorDisplayForm result

A way you may use me:

>>>  from ibm_watson_openscale import *
>>>  metrics = [
       MonitorMetricRequest(
           name='sensitivity',
           thresholds=[MetricThreshold(
               type=MetricThresholdTypes.LOWER_LIMIT,
               default=0.7
           )]
       ),
       MonitorMetricRequest(
           name='specificity',
           thresholds=[MetricThreshold(
               type=MetricThresholdTypes.LOWER_LIMIT,
               default=0.6
           )]
       ),
    ]
>>>  tags = [
       MonitorTagRequest(
           name='region',
           description='customer geographical region'.upper()
       )
    ]
>>>  my_monitor = client.monitor_definitions.update(
       monitor_definition_id='monitor_definition_id',
       name='my model performance',
       metrics=metrics,
       tags=tags)
show(limit: int = 10) None[source]

Show monitor definitions. By default 10 records will be shown.

Parameters

limit (int) – maximal number of fetched rows. By default set to 10. (optional)

A way you might use me is:

>>>  client.monitor_definitions.show()
>>>  client.monitor_definitions.show(limit=20)
>>>  client.monitor_definitions.show(limit=None)
get(monitor_definition_id: str, **kwargs) DetailedResponse

Get a specific monitor definition.

Get a specific monitor definition.

Parameters
  • monitor_definition_id (str) – Unique monitor definition ID.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorDisplayForm result

list(*, name: Optional[str] = None, **kwargs) DetailedResponse

List available monitors.

List available monitors.

Parameters
  • name (str) – (optional) comma-separeted list of names.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorCollections result

patch(monitor_definition_id: str, json_patch_operation: List[JsonPatchOperation], **kwargs) DetailedResponse

Update a monitor definition.

Update a monitor definition.

Parameters
  • monitor_definition_id (str) – Unique monitor definition ID.

  • json_patch_operation (List[JsonPatchOperation]) –

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse with MonitorDisplayForm result

APIClient.ai_metrics

class AIMetrics(ai_client: WatsonOpenScaleV2Adapter)[source]

Bases: object

compute_metrics(spark=None, configuration=None, data_frame=None, metric_aggregator=None, **kwargs)[source]

Compute research metrics based on the configuration. :param SparkSession spark: Spark session object to be used for computing metrics. :param dict configuration: Configuration for computing metrics. :param Union[DataFrame, pd.DataFrame] data_frame: data frame containing the data on which metrics to be computed. :return: Key/Value pair where key is the metric group name and value is an object consisting of the metric results for all individual metrics. :rtype: dict

This is how the configuration parameter dict will look like

>>>
from ibm_metrics_plugin.common.utils.constants import FairnessMetricType
configuration = {}
configuration['configuration'] = {
    "problem_type": "binary",
    "label_column": "Risk",
    "fairness": {
                    "metrics_configuration": {
                        FairnessMetricType.SPD.value: {
                            "features": [ ["Sex"],["Age"] ]
                        },
                        FairnessMetricType.SED.value: {
                            "features": [ ["Sex"],["Sex","Age"] ],
                            "concentration": 1.0
                        }
                    },
                    "protected_attributes": [
                        {
                            "feature": "Sex",
                            "reference_group": ["male"]
                        },
                        {
                            "feature": "Age",
                            "reference_group": [[26, 55],[56,75]]
                        }
                    ],
                    "favourable_label": ["No Risk"],
                    "unfavourable_label": ["Risk"]
                }
}

A way you might use me is: >>> client.ai_metrics.compute_metrics(spark, configuration, data_frame)

compute_metrics_as_job(spark_credentials: dict, configuration: dict, background=True, timeout=300, **kwargs)[source]

Compute research metrics as spark job on remote spark.

Parameters
  • spark_credentials (dict) – Remote spark connection information.

  • configuration (dict) – Configuration for computing metrics. Configuration also include the information about where to read data from. Eg: Hive or DB2.

Returns

Key/Value pair where key is the metric group name and value is an object consisting of the metric results for all individual metrics.

Return type

dict

This is how the parameters look like

>>>
spark_credentials = {
    "connection": {
        "endpoint": "<JOB_ENDPOINT>",
        "location_type": "cpd_iae",
        "display_name": "<IAE_INSTANCE_NAME>",
        "instance_id": "<IAE_INSTANCE_ID>",
        "volume": "<MY_VOLUME>"
    },
    "credentials": {
        "username": "admin",
        "apikey":"<API_KEY"
    }
}
from ibm_metrics_plugin.common.utils.constants import FairnessMetricType
metric_config = {
    "problem_type":"binary",
    "label_column" : "Risk",
    "fairness": {
                    "metrics_configuration": {
                        FairnessMetricType.SPD.value: {
                            "features": [ ["Sex"],["Age"] ]
                        }
                    },
                    "protected_attributes": [
                        {
                            "feature": "Sex",
                            "reference_group": ["male"],
                            "monitored_group": ["female"],
                            "threshold": 0.95,
                        },
                        {
                            "feature": "Age",
                            "reference_group": [[26, 55],[56,75]],
                            "monitored_group": [[18, 25]],
                            "threshold": 0.95,
                        },
                    ],
                    "favourable_label": ["No Risk"],
                    "unfavourable_label": ["Risk"],
                    "min_records": 100
                }
}
configuration = {
    "spark_settings": {
        "max_num_executors": 4,
        "executor_cores": 1,
        "executor_memory": "1",
        "driver_cores": 1,
        "driver_memory": "1"
    },
    "arguments": {
        "storage": {
            "type": "hive",
            "connection": {
                "location_type": "metastore",
                "metastore_url": "<METASTORE_URL>"
            }
        },
        "tables": [
            {
                "type": "training",
                "database": "<DB_NAME>",
                "schema": "",
                "table": "<TABLE_NAME>"
            }
        ]
    }
}
configuration['arguments']['metric_configuration'] = metric_config

A way you might use me is: >>> client.ai_metrics.compute_metrics_as_job(spark_credentials, configuration)

get_job_output(job_response)[source]

Check the metrics evaluation job status and return the output on completion.

fit_transformer(spark=None, configuration=None, data_frame=None, **kwargs)[source]

Train a metric transformer.

Parameters
  • spark (SparkSession) – Spark session object to be used for evaluation.

  • configuration (dict) – Configuration for fitting the transformer.

  • data_frame (Union[DataFrame, pd.DataFrame]) – Dataframe on which the transformer is to be trained upon.

Returns

Instance of WOSTransformer

Return type

WOSTransformer

This is how the configuration parameter dict will look like

>>>
from ibm_metrics_plugin.common.utils.constants import FairnessMetricType
configuration = {}
configuration["configuration"] = {
    "fairness": {
        "metrics_configuration": {
            FairnessMetricType.FST.value: {
                "params": {
                    "epsilon": 0.01,
                    "criteria": "MSP"
                },
                "features": {"probabilities": <PROBABILITY_COLUMN_NAME>, "protected": <PROTECTED_ATTRIBUTE_NAME>}
            }
        }
    }
}

A way you might use me is: >>> client.ai_metrics.fit_transformer(spark, configuration, data_frame)

fit_transformer_as_job(spark_credentials: dict, configuration: dict, **kwargs)[source]

Fit metric transformer as spark Job

Parameters
  • spark_credentials (dict) – Remote spark connection information.

  • configuration (dict) – Configuration for fitting the transformer. Configuration also include the information about where to read data from. Eg: Hive or DB2.

Returns

Instance of WOSTransformer

Return type

WOSTransformer

This is how the parameters look like

>>>
spark_credentials = {
    "connection": {
        "endpoint": "<JOB_ENDPOINT>",
        "location_type": "cpd_iae",
        "display_name": "<IAE_INSTANCE_NAME>",
        "instance_id": "<IAE_INSTANCE_ID>",
        "volume": "<MY_VOLUME>"
    },
    "credentials": {
        "username": "admin",
        "apikey":"<API_KEY"
    }
}
from ibm_metrics_plugin.common.utils.constants import FairnessMetricType
metric_config = {
    "problem_type":"binary",
    "label_column" : "Risk",
    "fairness": {
        "metrics_configuration": {
            FairnessMetricType.FST.value: {
                "params": {
                    "epsilon": 0.01,
                    "criteria": "MSP"
                },
                "features": {"probabilities": <PROBABILITY_COLUMN_NAME>, "protected": <PROTECTED_ATTRIBUTE_NAME>}
            }
        }
    }
}
configuration = {
    "spark_settings": {
        "max_num_executors": 4,
        "executor_cores": 1,
        "executor_memory": "1",
        "driver_cores": 1,
        "driver_memory": "1"
    },
    "arguments": {
        "storage": {
            "type": "hive",
            "connection": {
                "location_type": "metastore",
                "metastore_url": "<METASTORE_URL>"
            }
        },
        "tables": [
            {
                "type": "training",
                "database": "<DB_NAME>",
                "schema": "",
                "table": "<TABLE_NAME>"
            }
        ]
    }
}
configuration['arguments']['metric_configuration'] = metric_config

A way you might use me is:

>>> client.ai_metrics.fit_transformer_as_job(spark_credentials, configuration)
transform_result(metrics_result, metric_group_type, metric_type, **kwargs)[source]

Transform the json metric result to the required object. For SHAP metric, the result is transformed to SHAP explanation objects which can then be used to plot the explanations. An exception is thrown when invoked for metric which do not support transformation of result.

show_supported_fairness_metrics()[source]
show_supported_explainers()[source]

Helper Classes

MetricThreshold

class MetricThreshold(type: str, *, default: Optional[float] = None, default_recommendation: Optional[str] = None, specific_values: Optional[List[MetricSpecificThresholdObject]] = None)[source]

MetricThreshold.

Attr str type

Attr float default

(optional) default value of threshold.

Attr str default_recommendation

(optional)

Attr List[MetricSpecificThresholdObject] specific_values

(optional)

Target

class Target(target_type: str, target_id: str)[source]

Target.

Attr str target_type

Type of the target (e.g. subscription, business application, …).

Attr str target_id

ID of the data set target (e.g. subscription ID, business application ID, …).

MonitorInstanceParameters

DatabaseConfiguration

class DatabaseConfiguration(database_type: str, credentials: SecretCleaned, *, instance_id: Optional[str] = None, name: Optional[str] = None, location: Optional[LocationSchemaName] = None)[source]

Database configuration ignored if internal database is requested (internal_database is true).

Attr str database_type

Attr str instance_id

(optional)

Attr str name

(optional)

Attr SecretCleaned credentials

Attr LocationSchemaName location

(optional)

class DatabaseTypeEnum(value)[source]

database_type.

POSTGRESQL = 'postgresql'
DB2 = 'db2'

AzureCredentials

class AzureCredentials(*, token: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, subscription_id: Optional[str] = None, client_id: Optional[str] = None, client_secret: Optional[str] = None, tenant: Optional[str] = None, workspaces: Optional[List[AzureWorkspaceCredentials]] = None, **kwargs)[source]

AzureCredentials.

Attr str token

(optional)

Attr str username

(optional)

Attr str password

(optional)

Attr str subscription_id

(optional)

Attr str client_id

(optional)

Attr str client_secret

(optional)

Attr str tenant

(optional)

Attr List[AzureWorkspaceCredentials] workspaces

(optional)

CustomCredentials

class CustomCredentials(*, url: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, apikey: Optional[str] = None, auth_url: Optional[str] = None, auth_type: Optional[str] = None, auth_provider: Optional[str] = None, **kwargs)[source]

CustomCredentials.

Attr str url

(optional)

Attr str username

(optional)

Attr str password

(optional)

Attr str apikey

(optional)

Attr str auth_url

(optional)

Attr str auth_type

(optional)

Attr str auth_provider

(optional)

class AuthTypeEnum(value)[source]

auth_type.

BASIC = 'basic'
API_KEY = 'api_key'
class AuthProviderEnum(value)[source]

auth_provider.

CLOUD = 'cloud'
CPD = 'cpd'

SageMakerCredentials

class SageMakerCredentials(access_key_id: str, secret_access_key: str, *, region: Optional[str] = None, **kwargs)[source]

SageMakerCredentials.

Attr str access_key_id

Attr str secret_access_key

Attr str region

(optional)

SPSSCredentials

class SPSSCredentials(url: str, username: str, password: str, **kwargs)[source]

SPSSCredentials.

Attr str url

Attr str username

Attr str password

WMLCredentialsCP4D

class WMLCredentialsCP4D(*, url: Optional[str] = None, apikey: Optional[str] = None, username: Optional[str] = None, uid: Optional[str] = None, wml_location: Optional[str] = None, **kwargs)[source]

WMLCredentials format for OpenScale on Cloud Pak for Data.

Attr str url

(optional) Required if wml_location is cpd_remote or cloud_remote.

Attr str apikey

(optional) Required if wml_location is cpd_remote or cloud_remote.

Attr str username

(optional) Required if wml_location is cpd_remote.

Attr str uid

(optional) User ID of a user in the Cloud Pak for Data. If not set, the uid extracted from the access token in Authorization header is used. This parameter is only applicable if wml_location is cpd_local.

Attr str wml_location

(optional) If wml_location is not selected, we treat the service provider as cpd_local for backward compatibility.

class WmlLocationEnum(value)[source]

If wml_location is not selected, we treat the service provider as cpd_local for backward compatibility.

CPD_LOCAL = 'cpd_local'
CPD_REMOTE = 'cpd_remote'
CLOUD_REMOTE = 'cloud_remote'

WMLCredentialsCloud

class WMLCredentialsCloud(url: str, instance_id: str, *, apikey: Optional[str] = None, token: Optional[str] = None, **kwargs)[source]

WMLCredentialsCloud.

Attr str apikey

(optional)

Attr str token

(optional)

Attr str url

Attr str instance_id

Asset

class Asset(asset_id: str, asset_type: str, *, url: Optional[str] = None, name: Optional[str] = None, asset_rn: Optional[str] = None, created_at: Optional[str] = None, problem_type: Optional[str] = None, model_type: Optional[str] = None, runtime_environment: Optional[str] = None, input_data_type: Optional[str] = None)[source]

Asset.

Attr str asset_id

Attr str url

(optional)

Attr str name

(optional)

Attr str asset_type

Attr str asset_rn

(optional) Asset Resource Name (used for integration with 3rd party ML engines).

Attr str created_at

(optional)

Attr str problem_type

(optional)

Attr str model_type

(optional)

Attr str runtime_environment

(optional)

Attr str input_data_type

(optional)

AssetDeploymentRequest

class AssetDeploymentRequest(deployment_id: str, name: str, deployment_type: str, *, deployment_rn: Optional[str] = None, url: Optional[str] = None, description: Optional[str] = None, created_at: Optional[str] = None, scoring_endpoint: Optional[ScoringEndpointRequest] = None)[source]

AssetDeploymentRequest.

Attr str deployment_id

Attr str deployment_rn

(optional) Deployment Resource Name (used for integration with 3rd party ML engines).

Attr str url

(optional)

Attr str name

Attr str description

(optional)

Attr str deployment_type

Deployment type, e.g. online, batch.

Attr str created_at

(optional)

Attr ScoringEndpointRequest scoring_endpoint

(optional) Definition of scoring endpoint in custom_machine_learning.

AssetPropertiesRequest

class AssetPropertiesRequest(*, training_data_reference: Optional[TrainingDataReference] = None, training_data_schema: Optional[SparkStruct] = None, input_data_schema: Optional[SparkStruct] = None, output_data_schema: Optional[SparkStruct] = None, label_column: Optional[str] = None, labels: Optional[List[str]] = None, predicted_target_field: Optional[str] = None, prediction_field: Optional[str] = None, transaction_id_field: Optional[str] = None, dashboard_configuration: Optional[dict] = None, feature_fields: Optional[List[str]] = None, categorical_fields: Optional[List[str]] = None, probability_fields: Optional[List[str]] = None)[source]

Additional asset properties (subject of discovery if not provided when creating the subscription).

Attr TrainingDataReference training_data_reference

(optional)

Attr SparkStruct training_data_schema

(optional)

Attr SparkStruct input_data_schema

(optional)

Attr SparkStruct output_data_schema

(optional)

Attr str label_column

(optional)

Attr List[str] labels

(optional)

Attr str predicted_target_field

(optional) Field with this name will be given modeling_role decoded-target.

Attr str prediction_field

(optional) Field with this name will be given modeling_role prediction.

Attr str transaction_id_field

(optional) Field with this name will have transaction_id_key metadata set to true.

Attr dict dashboard_configuration

(optional)

Attr List[str] feature_fields

(optional) Fields to be given modeling_role feature.

Attr List[str] categorical_fields

(optional) Fields to be given metadata measure of value discrete.

Attr List[str] probability_fields

(optional) Fields to be given modeling_role class_probability (for columns of double data type) or probability (for column of array data type).

PayloadRecord

class PayloadRecord(request: dict, response: Union[dict, str], scoring_id: Optional[str] = None, scoring_timestamp: Optional[str] = None, response_time: Optional[int] = None, asset_revision: Optional[str] = None, multiple_records: bool = True)[source]

Used during payload logging, describes payload record.

Parameters
  • request (dict) – scoring request

  • response (int) – scoring response

  • scoring_id (str) – scoring identifier (optional). If not provided random uid is assigned.

  • scoring_timestamp (str) – scoring request timestamp (optional). If not provided current time is assigned.

  • response_time – scoring response time in ms (optional)

MonitorMeasurementMetrics

PrimaryStorageCredentialsLong

class PrimaryStorageCredentialsLong(hostname: str, username: str, password: str, db: str, *, port: Optional[int] = None, ssl: Optional[bool] = None, sslmode: Optional[str] = None, certificate_base64: Optional[str] = None, additional_properties: Optional[dict] = None)[source]

PrimaryStorageCredentialsLong.

Attr str hostname

Attr str username

Attr str password

Attr str db

Attr int port

(optional)

Attr bool ssl

(optional)

Attr str sslmode

(optional) (postgresql only).

Attr str certificate_base64

(optional) DER-encoded certificate in Base64 encoding. The decoded content must be bound at the beginning by —–BEGIN CERTIFICATE—– and at the end by —–END CERTIFICATE—–.

Attr dict additional_properties

(optional) any additional properties to be included in connection url.

JsonPatchOperation

class JsonPatchOperation(op: str, path: str, *, from_: Optional[str] = None, value: Optional[object] = None)[source]

This model represents an individual patch operation to be performed on a JSON document, as defined by RFC 6902.

Attr str op

The operation to be performed.

Attr str path

The JSON Pointer that identifies the field that is the target of the operation.

Attr str fromfrom_

(optional) The JSON Pointer that identifies the field that is the source of the operation.

Attr object value

(optional) The value to be used within the operation.

Enums

class InputDataType[source]

Bases: object

Describes possible model input data types.

Contains: [STRUCTURED, UNSTRUCTURED_IMAGE, UNSTRUCTURED_TEXT, UNSTRUCTURED_AUDIO, UNSTRUCTURED_VIDEO]

STRUCTURED = 'structured'
UNSTRUCTURED_IMAGE = 'unstructured_image'
UNSTRUCTURED_TEXT = 'unstructured_text'
UNSTRUCTURED_AUDIO = 'unstructured_audio'
UNSTRUCTURED_VIDEO = 'unstructured_video'
class DeploymentTypes[source]

Bases: object

Describes possible model deployment types.

Contains: [ONLINE]

ONLINE = 'online'
class RecordsFormatTypes[source]

Bases: object

Describes possible format types for getting list of records.

Contains: [DICT, LIST]

DICT = 'dict'
LIST = 'list'
class FeedbackType(value)[source]

Bases: Enum

Describes supported types of feedback format.

Contains: [WML, DICT, CSV]

WML = 'WML'
DICT = 'DICT'
CSV = 'CSV'
PAYLOAD = 'PAYLOAD'
LIST_OF_DICT = 'LIST_OF_DICT'
classmethod has_value(value)[source]
class ServiceTypes[source]

Bases: object

Describes supported types of service.

Contains: [WATSON_MACHINE_LEARNING, AMAZON_SAGEMAKER,

AZURE_MACHINE_LEARNING, CUSTOM_MACHINE_LEARNING, SPSS_COLLABORATION_AND_DEPLOYMENT_SERVICES, AZURE_MACHINE_LEARNING_SERVICE]

WATSON_MACHINE_LEARNING = 'watson_machine_learning'
AMAZON_SAGEMAKER = 'amazon_sagemaker'
AZURE_MACHINE_LEARNING = 'azure_machine_learning'
CUSTOM_MACHINE_LEARNING = 'custom_machine_learning'
SPSS_COLLABORATION_AND_DEPLOYMENT_SERVICES = 'spss_collaboration_and_deployment_services'
AZURE_MACHINE_LEARNING_SERVICE = 'azure_machine_learning_service'
class ResponseTypes[source]

Bases: object

Describes supported types of output format.

Contains: [PANDAS, PYTHON]

PANDAS = 'pandas'
PYTHON = 'python'
class TargetTypes[source]

Bases: object

Describes supported types of target format.

Contains: [SUBSCRIPTION, BUSINESS_APPLICATION, INSTANCE, DATA_MART]

SUBSCRIPTION = 'subscription'
BUSINESS_APPLICATION = 'business_application'
INSTANCE = 'instance'
DATA_MART = 'data_mart'
class FormatTypes[source]

Bases: object

Format of the returned data. full format compared to compact is additive and contains sources part.

COMPACT = 'compact'
FULL = 'full'
class IntervalTypes[source]

Bases: object

Time unit in which metrics are grouped and aggregated, interval by interval.

MINUTE = 'minute'
HOUR = 'hour'
DAY = 'day'
WEEK = 'week'
MONTH = 'month'
YEAR = 'year'
class AggregationTypes[source]

Bases: object

Comma delimited function list constructed from metric name and function, e.g. agg=metric_name:count,:last that defines aggregations.

LAST = 'last'
FIRST = 'first'
MAX = 'max'
MIN = 'min'
SUM = 'sum'
AVG = 'avg'
COUNT = 'count'
STDDEV = 'stddev'
class OnErrorTypes[source]

Bases: object

expected behaviour on error.

STOP = 'stop'
CONTINUE = 'continue'
class ContentTypes[source]

Bases: object

The type of the input. A character encoding can be specified by including a charset parameter. For example, ‘text/csv;charset=utf-8’.

APPLICATION_JSON = 'application/json'
TEXT_CSV = 'text/csv'
class DataSetTypes[source]

Bases: object

type of the data set.

MANUAL_LABELING = 'manual_labeling'
PAYLOAD_LOGGING = 'payload_logging'
FEEDBACK = 'feedback'
BUSINESS_PAYLOAD = 'business_payload'
CUSTOM = 'custom'
class MetricThresholdTypes[source]

Bases: object

LOWER_LIMIT = 'lower_limit'
UPPER_LIMIT = 'upper_limit'
class StatusStateType[source]

Bases: object

ACTIVE = 'active'
RUNNING = 'running'
FINISHED = 'finished'
PREPARING = 'preparing'
SUCCESS = 'success'
COMPLETED = 'completed'
FAILURE = 'failure'
FAILED = 'failed'
ERROR = 'error'
CANCELLED = 'cancelled'
CANCELED = 'canceled'
class DatabaseType[source]

Bases: object

Describes possible options of choosing database type.

Contains: [POSTGRESQL, DB2]

POSTGRESQL = 'postgresql'
DB2 = 'db2'
class Choose[source]

Bases: object

Describes possible options of choosing result from table filtering when only one result is required.

Contains: [FIRST, LAST, RANDOM]

FIRST = 'first'
LAST = 'last'
RANDOM = 'random'
class ProblemType[source]

Bases: object

Describes possible model (problem) types.

Contains: [regression, binary, multiclass]

REGRESSION = 'regression'
BINARY_CLASSIFICATION = 'binary'
MULTICLASS_CLASSIFICATION = 'multiclass'
class AssetTypes[source]

Bases: object

MODEL = 'model'
FUNCTION = 'function'
class ExpectedDirectionTypes[source]

Bases: object

the indicator specifying the expected direction of the monotonic metric values.

INCREASING = 'increasing'
DECREASING = 'decreasing'
UNKNOWN = 'unknown'
class SchemaUpdateModeTypes[source]

Bases: object

NONE = 'none'
AUTO = 'auto'
class IntegratedSystemTypes[source]

Bases: object

OPEN_PAGES = 'open_pages'
WATSON_DATA_CATALOG = 'watson_data_catalog'
SLACK = 'slack'
class OperationTypes[source]

Bases: object

The operation to be performed.

ADD = 'add'
REMOVE = 'remove'
REPLACE = 'replace'
MOVE = 'move'
COPY = 'copy'
TEST = 'test'
class ScheduleRepeatTypes[source]

Bases: object

The type of interval to monitor the target.

MINUTE = 'minute'
HOUR = 'hour'
DAY = 'day'
WEEK = 'week'
MONTH = 'month'
YEAR = 'year'
class TriggerTypes[source]

Bases: object

An identifier representing the source that triggered the run request (optional). One of: event, scheduler, user, webhook.

EVENT = 'event'
SCHEDULER = 'scheduler'
USER = 'user'
WEBHOOK = 'webhook'
BKPI_MANAGER = 'bkpi_manager'
class NotificationServiceTypes[source]

Bases: object

The messaging service to use, for example, slack or email, or list_ref to indicate a previously created notification list.

SLACK = 'slack'
EMAIL = 'email'
LIST_REF = 'list_ref'
class MessageFormatTypes[source]

Bases: object

The format of the message text.

TEXT = 'text'
HTML = 'html'
class PayloadFieldTypes[source]

Bases: object

STRING = 'string'
NUMBER = 'number'
class TrainingDataReferenceType[source]

Bases: object

Type of the storage.

DB2 = 'db2'
COS = 'cos'
class CP4DWMLLocation[source]

Bases: object

CP4D WML Location.

CPD_LOCAL = 'cpd_local'
CPD_REMOTE = 'cpd_remote'
CLOUD_REMOTE = 'cloud_remote'
class FairnessMetrics(value)[source]

Bases: Enum

An enumeration.

DISPARATE_IMPACT = 'fairness_value'
STATISTICAL_PARITY_DIFFERENCE = 'statistical_parity_difference'
AVERAGE_ODDS_DIFFERENCE = 'average_odds_difference'
AVERAGE_ABS_ODDS_DIFFERENCE = 'average_abs_odds_difference'
FALSE_NEGATIVE_RATE_DIFFERENCE = 'false_negative_rate_difference'
FALSE_POSITIVE_RATE_DIFFERENCE = 'false_positive_rate_difference'
FALSE_DISCOVERY_RATE_DIFFERENCE = 'false_discovery_rate_difference'
FALSE_OMISSION_RATE_DIFFERENCE = 'false_omission_rate_difference'
ERROR_RATE_DIFFERENCE = 'error_rate_difference'

Sample Monitor Instance Payloads

Quality

    target = Target(
                target_type=TargetTypes.SUBSCRIPTION,
                target_id=<SUBSCRIPTION_ID>
            )
    parameters =  {
                "min_feedback_data_size": 200
            }
        thresholds =  [{
                "metric_id": "area_under_roc",
                "type": "lower_limit",
                "value": 0.75
            }]
    ai_client.monitor_instances.create(
    data_mart_id=<DATAMART_ID>,
    background_mode=False,
    monitor_definition_id=ai_client.monitor_definitions.MONITORS.QUALITY.ID,
    target=target,
    parameters=parameters,
    thresholds=thresholds
)

Drift

    target = Target(
    target_type=TargetTypes.SUBSCRIPTION,
    target_id=<SUBSCRIPTION_ID>
    )
    parameters = {
        "min_samples": 1000,
        "drift_threshold": 0.1,
        "train_drift_model": True,
        "enable_data_drift": True,
        "enable_model_drift": True,
        "model_name": "<archive_name_to_be_used>"
}
ai_client.monitor_instances.create(
    data_mart_id=<DATAMART_ID>,
    background_mode=False,
    monitor_definition_id=ai_client.monitor_definitions.MONITORS.DRIFT.ID,
    target=target,
    parameters=parameters,
    thresholds=thresholds
)

Explanation

target = Target(
    target_type=TargetTypes.SUBSCRIPTION,
    target_id=<SUBSCRIPTION_ID>
    )
parameters = {
    "enabled":True
}
ai_client.monitor_instances.create(
    data_mart_id=<DATAMART_ID>,
    background_mode=False,
    monitor_definition_id=ai_client.monitor_definitions.MONITORS.EXPLAINABILITY.ID,
    target=target,
    parameters=parameters
)

Fairness

    parameters =  {
    "class_label": "predictedLabel",
    "favourable_class": [
        "No Risk"
    ],
    "features": [{
        "feature": "Age",
        "majority": [
            [
                19,
                43
            ]
        ],
        "minority": [
            [
                44,
                67
            ]
        ]
    }],
    "unfavourable_class": [
        "Risk"
    ],
    "min_records": 100
}

thresholds =  [{
    "metric_id": "fairness_value",
    "specific_values": [{
        "applies_to": [{
            "key": "feature",
            "type": "tag",
            "value": "Age"
        }],
        "value": 90.0
    }],
    "type": "lower_limit",
    "value": 90.0
}]

target = Target(
    target_type=TargetTypes.SUBSCRIPTION,
    target_id=<SUBSCRIPTION_ID>
    )
ai_client.monitor_instances.create(
    data_mart_id=<DATAMART_ID>,
    background_mode=False,
    monitor_definition_id=ai_client.monitor_definitions.MONITORS.FAIRNESS.ID,
    target=target,
    parameters=parameters,
    thresholds=thresholds )