IBM Watson Machine Learning Client

1.0.368 · maintenance · verified Thu Apr 16

The `ibm-watson-machine-learning` library provides a Python API client for interacting with the IBM Watson Machine Learning service on IBM Cloud and IBM Cloud Pak for Data. It enables users to programmatically train, test, store, and deploy machine learning models as APIs. The library is currently in maintenance mode (as of IBM Cloud Pak for Data 5.0.x, June 2024), with a recommendation to migrate to the `ibm-watsonx-ai` package for enhanced functionalities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `APIClient` for the IBM Watson Machine Learning service. It assumes you have an IBM Cloud API Key and the service endpoint URL, or equivalent credentials for IBM Cloud Pak for Data. The code includes placeholders for environment variables or direct replacement. Successful initialization means the client can then be used to interact with various WML functionalities like managing models, deployments, and experiments.

import os
from ibm_watson_machine_learning.APIClient import APIClient

# --- IMPORTANT: This library is in maintenance mode. Consider ibm-watsonx-ai ---

# Replace with your IBM Cloud API Key and Watson Machine Learning service endpoint.
# For IBM Cloud: API_KEY and the service_endpoint (e.g., 'https://us-south.ml.cloud.ibm.com')
# For Cloud Pak for Data: USERNAME, PASSWORD, and service_endpoint (e.g., 'https://<your_cpd_cluster_host>')

# Example for IBM Cloud (API Key authentication):
api_key = os.environ.get('IBM_CLOUD_API_KEY', 'YOUR_IBM_CLOUD_API_KEY')
service_endpoint = os.environ.get('WML_SERVICE_ENDPOINT', 'https://us-south.ml.cloud.ibm.com') # Example endpoint

if 'YOUR_IBM_CLOUD_API_KEY' in api_key or 'YOUR_CPD_CLUSTER_HOST' in service_endpoint:
    print("Please set IBM_CLOUD_API_KEY and WML_SERVICE_ENDPOINT environment variables or replace placeholders.")
else:
    try:
        wml_credentials = {
            "apikey": api_key,
            "url": service_endpoint
        }

        client = APIClient(wml_credentials)
        print("IBM Watson Machine Learning client initialized successfully.")
        print(f"Client version: {client.version}")

        # Example: Get spaces (requires a WML service instance and configured spaces)
        # spaces = client.spaces.get_details()
        # print("Available WML Spaces:")
        # for space in spaces['resources']:
        #     print(f"- {space['entity']['name']} (ID: {space['metadata']['id']})")

    except Exception as e:
        print(f"Error initializing WML client: {e}")
        print("Ensure your API key and service endpoint are correct and you have access to the service.")

view raw JSON →