This is a migration guide for developers to migrate their existing assets from WML v3/v4 beta to WML v4.
- Specifying credentials
- Creating a client object
- Creating deployment space and setting up default deployement space for your project
- Specifying metadata for storing the model
- Storing a model (remains same)
- Specifying metadata for deployment (remains same)
- Specifying input payload for prediction (remains same)
- Getting predictions (remains same)
wml_credentials = {
"apikey":"",
"url": "",
"instance_id": ""
}
NEW: Apikey has to be generated from IBM Cloud > Resources > WML Instance > Manage > Access (IAM) > API keys > Create an IBM Cloud API key
NOTE:
instance_id
is no longer required.url
will change based on the region where the WML Instance is deployed in your IBM Cloud, Example:- London: https://eu-gb.ml.cloud.ibm.com
- Dallas: https://us-south.ml.cloud.ibm.com
apikey = "<APIKEY_FROM_IAM>"
wml_credentials = {
"apikey": apikey,
"url": "https://eu-gb.ml.cloud.ibm.com"
}
OLD: The watson_machine_learning_client
and WatsonMachineLearningAPIClient
libraries were used in v3 / v4 beta.
from watson_machine_learning_client import WatsonMachineLearningAPIClient
client = WatsonMachineLearningAPIClient(wml_credentials)
!pip install -U ibm-watson-machine-learning
from ibm_watson_machine_learning import APIClient
client = APIClient(wml_credentials)
-
In IBM Cloud, goto resources and select Watson Studio instance, click on Get Started to launch Watson Studio / Cloud Pak for Data.
-
In Watson Studio / Cloud Pak for Data, click on the hamburger menu on the top left corner and select Deployment spaces > View all spaces.
-
In deployment spaces, click on New deployment space +.
-
Select Create an empty space when prompted.
-
Make sure you select the appropriate Cloud object storage service as well as Machine learning service.
NOTE: In v4 Machine learning assets are stored in Cloud Object Storage rather than in the Watson Machine Learning repository.
-
Once the deployment space is created, click on View Space to view the details.
-
Click on Settings and copy the
space ID
.
Learn more about deployment space here.
space_id = "<DEPLOYMENT_SPACE_ID_FROM_WATSON_STUDIO>"
NEW: The deployment space id that you specified in the above step has to be set as the default deployment space for the project.
client.spaces.list(limit=10)
client.set.default_space(space_id)
metadata = {
client.repository.ModelMetaNames.NAME: 'Personal Loan Prediction Model',
client.repository.ModelMetaNames.TYPE: "scikit-learn_0.20",
client.repository.ModelMetaNames.RUNTIME_UID: "scikit-learn_0.20-py3.6"
}
sofware_spec_uid = client.software_specifications.get_id_by_name("default_py3.7")
metadata = {
client.repository.ModelMetaNames.NAME: 'Personal Loan Prediction model',
client.repository.ModelMetaNames.TYPE: 'scikit-learn_0.23',
client.repository.ModelMetaNames.SOFTWARE_SPEC_UID: sofware_spec_uid
}
Optionally, to get a list of software specifications run the following:
client.software_specifications.list()
published_model = client.repository.store_model(model=naive_model, meta_props=metadata, \
training_data=train_set, training_target=train_labels)
import json
published_model_uid = client.repository.get_model_uid(published_model)
model_details = client.repository.get_details(published_model_uid)
print(json.dumps(model_details, indent=2))
deploy_meta = {
client.deployments.ConfigurationMetaNames.NAME: 'Deployment of Personal Loan Prediction',
client.deployments.ConfigurationMetaNames.ONLINE: {}
}
created_deployment = client.deployments.create(published_model_uid, meta_props=deploy_meta)
deployments = client.deployments.get_details()
job_payload = {
client.deployments.ScoringMetaNames.INPUT_DATA: [{
'values': [[39,139,95616,3,3.4,1,483,0,0,1,0]]
}]
}
did = client.deployments.get_uid(created_deployment)
predictions = client.deployments.score(did, job_payload)
print(json.dumps(predictions, indent=2))
print(predictions["predictions"][0]['values'][0][0])