Path: blob/master/cloud/notebooks/rest_api/curl/experiments/autoai/Use AutoAI and batch deployment to predict credit risk.ipynb
6408 views
Use AutoAI and batch deployment to predict credit risk with Watson Machine Learning REST API
This notebook contains steps and code to demonstrate support of AutoAI experiments in Watson Machine Learning Service. It introduces commands for getting data, training experiments, persisting pipelines, publishing models, deploying models and scoring.
Some familiarity with cURL is helpful. This notebook uses cURL examples.
Learning goals
The learning goals of this notebook are:
Working with Watson Machine Learning experiments to train AutoAI models.
Downloading computed models to local storage.
Batch deployment and scoring of trained model.
Contents
This notebook contains the following parts:
1. Set up the environment
Before you use the sample code in this notebook, you must perform the following setup tasks:
Create a Watson Machine Learning (WML) Service instance (a free plan is offered and information about how to create the instance can be found here).
Create a Cloud Object Storage (COS) instance (a lite plan is offered and information about how to order storage can be found here).
Note: When using Watson Studio, you already have a COS instance associated with the project you are running the notebook in.
You can find your COS credentials in COS instance dashboard under the Service credentials tab. Go to the Endpoint tab in the COS instance's dashboard to get the endpoint information.
Authenticate the Watson Machine Learning service on IBM Cloud.
Your Cloud API key can be generated by going to the Users section of the Cloud console. From that page, click your name, scroll down to the API Keys section, and click Create an IBM Cloud API key. Give your key a name and click Create, then copy the created key and paste it below.
NOTE: You can also get service specific apikey by going to the Service IDs section of the Cloud Console. From that page, click Create, then copy the created key and paste it below.
Action: Fill below information to get started with this notebook.
<a href="https://cloud.ibm.com/apidocs/data-ai-common-core#spaces-create" target="_blank" rel="noopener no referrer">Space creation
Space creation is asynchronous. This means that you need to check space creation status after creation call. Make sure that your newly created space is active
.
<a href="https://cloud.ibm.com/apidocs/data-ai-common-core#spaces-get" target="_blank" rel="noopener no referrer">Get space information
2. Experiment / optimizer configuration
Provide input information for AutoAI experiment / optimizer:
name
- experiment namelearning_type
- type of the problemlabel
- target column namescorer_for_ranking
- optimization metricholdout_param
- percentage of training data to use as a holdout [0 - 1]daub_include_only_estimators
- list of estimators to use
You can modify parameters
section of the following cURL call to change AutoAI experiment settings.
<a href="https://cloud.ibm.com/apidocs/machine-learning#pipelines-create" target="_blank" rel="noopener no referrer">Define AutoAI experiment.
<a href="https://cloud.ibm.com/apidocs/machine-learning#pipelines-get" target="_blank" rel="noopener no referrer">Get experiment / optimizer information
Training data connection
Define connection information to COS bucket and training data CSV file. This example uses the German Credit Risk dataset.
The dataset can be downloaded from here. You can also download it to local filesystem by running the cell below.
Action: Upload training data to COS bucket and enter location information in the next cURL examples.
<a href="https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-curl#curl-token" target="_blank" rel="noopener no referrer">Retrieve COS authentication token
<a href="https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-curl#curl-put-object" target="_blank" rel="noopener no referrer">Upload file to COS
There should be an empty response when upload finished succesfully.
Create connection to COS
Created connection will be used in training as a reference to given COS location.
Connections to external databases.
If you want to create experiment using data saved in the external database instead of COS,
you should change the following properties in the CONNECTION_PAYLOAD
:
datasource_type
properties
Where properties
key should contain credentials required for the connection creation which should follow the bellow pattern:
The datasource_type
list can be obtained by using bellow request.
Exemplary payload for DB2 database:
<a href="https://cloud.ibm.com/apidocs/machine-learning#trainings-create" target="_blank" rel="noopener no referrer">Schedule a training job for AutoAI experiment
<a href="https://cloud.ibm.com/apidocs/machine-learning#trainings-get" target="_blank" rel="noopener no referrer">Get information about training job
Get training status
Please make sure that training is completed before you go to the next sections. Monitor state
of your training by running above cell couple of times.
Output should be similar to the output from training creation but you should see more trainings entries. Listing trainings:
<a href="https://cloud.ibm.com/apidocs/machine-learning#trainings-list" target="_blank" rel="noopener no referrer">Get list of historical training jobs information
<a href="https://cloud.ibm.com/apidocs/machine-learning#trainings-delete" target="_blank" rel="noopener no referrer">Canceling training
Before deployment creation, you need store your model in WML repository. Please see below cURL call example how to do it. Remember that you need to specify where your chosen model is stored in COS.
<a href="https://cloud.ibm.com/apidocs/machine-learning#models-create" target="_blank" rel="noopener no referrer">Model storing
<a href="https://cloud.ibm.com/apidocs/machine-learning#models-filtered-download" target="_blank" rel="noopener no referrer">Download model content
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployments-create" target="_blank" rel="noopener no referrer">Create deployment
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployments-get" target="_blank" rel="noopener no referrer">Get deployment details
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployment-jobs-create" target="_blank" rel="noopener no referrer">Create deployment job
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployment-jobs-list" target="_blank" rel="noopener no referrer">List jobs
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployment-jobs-get" target="_blank" rel="noopener no referrer">Get job details
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployment-jobs-delete" target="_blank" rel="noopener no referrer">Cancel job
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployments-list" target="_blank" rel="noopener no referrer">List deployments details
<a href="https://cloud.ibm.com/apidocs/machine-learning#trainings-delete" target="_blank" rel="noopener no referrer">Deleting training
<a href="https://cloud.ibm.com/apidocs/machine-learning#deployment-jobs-delete" target="_blank" rel="noopener no referrer">Delete job
<a href="https://cloud.ibm.com/apidocs/machine-learning#models-delete" target="_blank" rel="noopener no referrer">Delete model from repository
Authors
Amadeusz Masny, Python Software Developer in Watson Machine Learning at IBM Jan Sołtysik, Intern in Watson Machine Learning at IBM
Copyright © 2020, 2021, 2022 IBM. This notebook and its source code are released under the terms of the MIT License.