Path: blob/master/cpd4.0/notebooks/python_sdk/experiments/autoai/Use AutoAI with Watson Studio project.ipynb
6383 views
Use AutoAI with Watson Studio project ibm-watson-machine-learning
This notebook contains the steps and code to demonstrate support of AutoAI experiments in Watson Machine Learning service inside Watson Studio's projects. It introduces commands for data retrieval, training experiments and scoring.
Some familiarity with Python is helpful. This notebook uses Python 3.9.
Learning goals
The learning goals of this notebook are:
Work with Watson Machine Learning experiments to train AutoAI model using Watson Studio project.
Online, Batch deployment and score the trained model trained.
Contents
This notebook contains the following parts:
Connection to WML
Authenticate the Watson Machine Learning service on IBM Cloud Pack for Data. You need to provide platform url
, your username
and api_key
.
Alternatively you can use username
and password
to authenticate WML services.
Install and import the ibm-watson-machine-learning
package
Note: ibm-watson-machine-learning
documentation can be found here.
Working with spaces
First of all, you need to create a space that will be used for your work. If you do not have space already created, you can use {PLATFORM_URL}/ml-runtime/spaces?context=icp4data
to create one.
Click New Deployment Space
Create an empty space
Go to space
Settings
tabCopy
space_id
and paste it below
Tip: You can also use SDK to prepare the space for your work. More information can be found here.
Action: Assign space ID below
You can use the list
method to print all existing spaces.
Working with projects
First of all, you need to create a project that will be used for your work. If you do not have space already created follow bellow steps.
Open IBM Cloud Pak main page
Click all projects
Create an empty project
Copy
project_id
from url and paste it below
Action: Assign project ID below
To be able to interact with all resources available in Watson Machine Learning, you need to set the project which you will be using.
Training data connection
Define connection information to training data CSV file. This example uses the German Credit Risk dataset.
The dataset can be downloaded from here.
Optimizer configuration
Provide the input information for AutoAI optimizer:
name
- experiment nameprediction_type
- type of the problemprediction_column
- target column namescoring
- optimization metric
Configuration parameters can be retrieved via get_params()
.
You can use the get_run_status()
method to monitor AutoAI jobs in background mode.
You can visualize the scoring metric calculated on a holdout data set.
Webservice deployment creation
Deployment object could be printed to show basic information:
To show all available information about the deployment use the .get_params()
method:
Scoring of webservice
You can make scoring request by calling score()
on deployed pipeline.
If you want to work with the web service in an external Python application you can retrieve the service object by:
Initialize the service by
service = WebService(wml_credentials)
Get deployment_id by
service.list()
methodGet webservice object by
service.get('deployment_id')
method
After that you can call service.score()
method.
Deleting deployment
You can delete the existing deployment by calling the service.delete()
command. To list the existing web services you can use service.list()
.
Batch deployment creation
A batch deployment processes input data from a inline data and return predictions in scoring details or processes from data asset and writes the output to a file.
Create batch deployment for Pipeline_2
created in AutoAI experiment with the run_id
.
Score batch deployment with inline payload as pandas DataFrame.
Deleting deployment
You can delete the existing deployment by calling the service_batch.delete()
command. To list the existing:
batch services you can use
service_batch.list()
,scoring jobs you can use
service_batch.list_jobs()
.
If you want to clean up all created assets:
experiments
trainings
pipelines
model definitions
models
functions
deployments
please follow up this sample notebook.
6. Summary and next steps
You successfully completed this notebook!.
You learned how to use ibm-watson-machine-learning
to run AutoAI experiments using project.
Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Jan Sołtysik, Intern in Watson Machine Learning
Copyright © 2020-2025 IBM. This notebook and its source code are released under the terms of the MIT License.