This tutorial creates two machine learning models with IBM Watson Studio. The first is created in the UI and the second in Jupyter Notebook using scikit-learn. We will save and deploy bother models on IBM Cloud.
1. Introduction to MachineIntroduction to Machine
Learning on IBM WatsonLearning on IBM Watson
StudioStudio
Upkar Lidder
Developer Advocate, IBM
> ulidder@us.ibm.com
> @lidderupk
> upkar.dev http://bit.ly/waston-ml-sign
2. PrerequisitesPrerequisites
@lidderupkIBM Developer
1. Create IBM Cloud Account using THIS URL
3. If you already have an account, use the above URL to sign into your
IBM Cloud account.
2. Check your email and activate your account. Once activated, log back
into your IBM Cloud account using the link above.
http://bit.ly/waston-ml-sign
3. Watson Studio & Watson Machine LearningWatson Studio & Watson Machine Learning
@lidderupkIBM Developer
7. Workshop -Workshop - GoalsGoals
@lidderupkIBM Developer
Successfully Create, Store and
Deploy a Linear Regression Model
on IBM Cloud using Watson Studio
and Watson Machine Learning
Services.
8. Question -Question - predict median house price for Boston areapredict median house price for Boston area
@lidderupkIBM Developer
10. StepsSteps
@lidderupkIBM Developer
1. Sign up / Log into IBM Cloud - http://bit.ly/waston-ml-sign
2. Create Watson Studio Service.
3. Sign into Watson Studio and create a new Data Science
Project. It also creates a Cloud Object Store for you.
4. Associate a Machine Learning Service with your project.
5. Upload csv data to your project.
6. Add a new Machine Learning Model to your project.
7. Create a Linear Regression Model and save it to IBM Cloud.
8. Create a new deployment on IBM Cloud.
9. Test your model !
11. Step 1 -Step 1 - sign up/ log into IBM Cloudsign up/ log into IBM Cloud
@lidderupkIBM Developer
http://bit.ly/waston-ml-sign
12. Step 2 -Step 2 - locate Watson Studio in Cataloglocate Watson Studio in Catalog
@lidderupkIBM Developer
13. Step 3 -Step 3 - create Watson Studio instancecreate Watson Studio instance
@lidderupkIBM Developer
19. Step 9 -Step 9 - drag and drop data file into Load Assetsdrag and drop data file into Load Assets
@lidderupkIBM Developer
http://bit.ly/boston-house-csv
20. Step 10 -Step 10 - add Machine Learning model to the projectadd Machine Learning model to the project
@lidderupkIBM Developer
21. Step 11 - associate a ML instanceStep 11 - associate a ML instance
@lidderupkIBM Developer
22. Step 12a -Step 12a - create ML instance if you don't have onecreate ML instance if you don't have one
@lidderupkIBM Developer
23. Step 12b -Step 12b - create a new lite ML instancecreate a new lite ML instance
@lidderupkIBM Developer
50. WML -WML - get Machine Learning service credentialsget Machine Learning service credentials
@lidderupkIBM Developer
51. WML -WML - save scikit-learn linear regression modelsave scikit-learn linear regression model
@lidderupkIBM Developer
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard4
wml_credentials = {5
}6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
52. WML -WML - save scikit-learn linear regression modelsave scikit-learn linear regression model
@lidderupkIBM Developer
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard4
wml_credentials = {5
}6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard
wml_credentials = {
}
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
4
5
6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
53. WML -WML - save scikit-learn linear regression modelsave scikit-learn linear regression model
@lidderupkIBM Developer
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard4
wml_credentials = {5
}6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard
wml_credentials = {
}
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
4
5
6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
# Instantiate WatsonMachineLearningAPIClient
from watson_machine_learning_client import WatsonMachineLearningAPIClient
client = WatsonMachineLearningAPIClient( wml_credentials )
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard4
wml_credentials = {5
}6
7
8
9
10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
54. WML -WML - save scikit-learn linear regression modelsave scikit-learn linear regression model
@lidderupkIBM Developer
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard4
wml_credentials = {5
}6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard
wml_credentials = {
}
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
4
5
6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
# Instantiate WatsonMachineLearningAPIClient
from watson_machine_learning_client import WatsonMachineLearningAPIClient
client = WatsonMachineLearningAPIClient( wml_credentials )
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard4
wml_credentials = {5
}6
7
8
9
10
11
# store the model12
published_model = client.repository.store_model(model=LR_model,13
meta_props={'name':'upkar-housing-linear-reg'},14
training_data=X_train, training_target=y_train)15
# store the model
published_model = client.repository.store_model(model=LR_model,
meta_props={'name':'upkar-housing-linear-reg'},
training_data=X_train, training_target=y_train)
# we will use WML to work with IBM Machine Learning Service1
from watson_machine_learning_client import WatsonMachineLearningAPIClient2
3
# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard4
wml_credentials = {5
}6
7
# Instantiate WatsonMachineLearningAPIClient8
from watson_machine_learning_client import WatsonMachineLearningAPIClient9
client = WatsonMachineLearningAPIClient( wml_credentials )10
11
12
13
14
15
55. WML -WML - deploy scikit-learn linear regression modeldeploy scikit-learn linear regression model
@lidderupkIBM Developer
import json1
2
# grab the model from IBM Cloud3
published_model_uid = client.repository.get_model_uid(published_model)4
5
# create a new deployment for the model6
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
56. WML -WML - deploy scikit-learn linear regression modeldeploy scikit-learn linear regression model
@lidderupkIBM Developer
import json1
2
# grab the model from IBM Cloud3
published_model_uid = client.repository.get_model_uid(published_model)4
5
# create a new deployment for the model6
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
# grab the model from IBM Cloud
published_model_uid = client.repository.get_model_uid(published_model)
# create a new deployment for the model
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")
import json1
2
3
4
5
6
7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
57. WML -WML - deploy scikit-learn linear regression modeldeploy scikit-learn linear regression model
@lidderupkIBM Developer
import json1
2
# grab the model from IBM Cloud3
published_model_uid = client.repository.get_model_uid(published_model)4
5
# create a new deployment for the model6
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
# grab the model from IBM Cloud
published_model_uid = client.repository.get_model_uid(published_model)
# create a new deployment for the model
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")
import json1
2
3
4
5
6
7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
#get the scoring endpoint
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)
print(scoring_endpoint)
import json1
2
# grab the model from IBM Cloud3
published_model_uid = client.repository.get_model_uid(published_model)4
5
# create a new deployment for the model6
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")7
8
9
10
11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
58. WML -WML - deploy scikit-learn linear regression modeldeploy scikit-learn linear regression model
@lidderupkIBM Developer
import json1
2
# grab the model from IBM Cloud3
published_model_uid = client.repository.get_model_uid(published_model)4
5
# create a new deployment for the model6
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
# grab the model from IBM Cloud
published_model_uid = client.repository.get_model_uid(published_model)
# create a new deployment for the model
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")
import json1
2
3
4
5
6
7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
#get the scoring endpoint
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)
print(scoring_endpoint)
import json1
2
# grab the model from IBM Cloud3
published_model_uid = client.repository.get_model_uid(published_model)4
5
# create a new deployment for the model6
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")7
8
9
10
11
12
#use the scoring endpoint to predict house median price some test data13
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}14
predictions = client.deployments.score(scoring_endpoint, scoring_payload)15
print(json.dumps(predictions, indent=2))16
#use the scoring endpoint to predict house median price some test data
scoring_payload = {"values": [list(X_test[0]), list(X_test[1])]}
predictions = client.deployments.score(scoring_endpoint, scoring_payload)
print(json.dumps(predictions, indent=2))
import json1
2
# grab the model from IBM Cloud3
published_model_uid = client.repository.get_model_uid(published_model)4
5
# create a new deployment for the model6
model_deployed = client.deployments.create(published_model_uid, "Deployment of scikit model")7
8
#get the scoring endpoint9
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)10
print(scoring_endpoint)11
12
13
14
15
16
59. WML -WML - deploy scikit-learn linear regression modeldeploy scikit-learn linear regression model
@lidderupkIBM Developer
60. WML -WML - try it out on your own !try it out on your own !
@lidderupkIBM Developer
http://bit.ly/waston-ml-sign
61. @lidderupkIBM Developer
WML -WML - create a new notebook from URLcreate a new notebook from URL
Grab the FULL URL from : http://bit.ly/boston-house-notebook
62. Thank youThank you
Let's chat !Let's chat !
@lidderupkIBM Developer
Upkar Lidder, IBM
@lidderupk
https://github.com/lidderupk/
ulidder@us.ibm.com