Introduction to Machine Learning on IBM Watson Studio

Lisa Jung
Upkar Lidder

http://bit.ly/ibm-cloud-summit-2019

IBM Developer

http://bit.ly/upkar-autoai

> ulidder@us.ibm.com
> @lidderupk
> upkar.dev

Prerequisites

@lidderupk
IBM 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/ibm-cloud-summit-2019

ML Hype

@lidderupk
IBM Developer

ML Map - scikit-learn

@lidderupk
IBM Developer

Unsupervised Learning

Supervised Learning

  • Classification
  • Regression
  • Clustering
  • Dimensionality Reduction

ML Lifecycle

@lidderupk
IBM Developer

Watson Studio & Watson Machine Learning

@lidderupk
IBM Developer

Watson Studio

IBM Watson Studio 

@lidderupk
IBM Developer

AutoAI

@lidderupk
IBM Developer

IBM Watson Studio - project based development platform 

@lidderupk
IBM Developer

Workshop - Goals

@lidderupk
IBM Developer
Successfully Create, Store and Deploy a Linear Regression Model on IBM Cloud using Watson Studio and Watson Machine Learning Services.

Question - predict median house price [MEDV] for Boston area

@lidderupk
IBM Developer

http://bit.ly/boston-house-csv

Linear regression - try to fit a line

@lidderupk
IBM Developer

Median House Price

Property Tax

Y = ⍺ + βx

Linear regression - loss function to get best fit

@lidderupk
IBM Developer

Steps

@lidderupk
IBM Developer
  1. Sign up / Log into IBM Cloud - http://bit.ly/ibm-ml
  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. Upload csv data to your project.
  5. Add a new AutoAI Experiment to your project.
  6. Create a ML Model and save it to IBM Cloud.
  7. Create a new deployment on IBM Cloud.
  8. Test your model !

Step 1 - sign up/ log into IBM Cloud

@lidderupk
IBM Developer

Step 2 - locate Watson Studio in Catalog

@lidderupk
IBM Developer

Step 3 - create Watson Studio instance

@lidderupk
IBM Developer

Step 3 - already have Watson Studio? Find it in Resources

@lidderupk
IBM Developer

Step 4 - launch Watson Studio

@lidderupk
IBM Developer

Step 5 - create a new project

@lidderupk
IBM Developer

Step 6 - pick Data Science starter

@lidderupk
IBM Developer

Step 6a - pick region [US South]

@lidderupk
IBM Developer

Step 7 - give the project a name and assign COS

@lidderupk
IBM Developer

Step 8 - open asset tab, this is your goto page!

@lidderupk
IBM Developer

Step 9 - create a new AutoAI experiment

@lidderupk
IBM Developer

Step 10 - adding training data

@lidderupk
IBM Developer

http://bit.ly/boston-house-csv

Step 11 - pick target column to predict [MEDV]

@lidderupk
IBM Developer

Step 11a - change model and metric if needed

@lidderupk
IBM Developer

Step 12 - run experiment

@lidderupk
IBM Developer

Step 13a - sit back and relax!

@lidderupk
IBM Developer

Step 13b - explore different models in the pipeline

@lidderupk
IBM Developer

Step 14 - save the best model

@lidderupk
IBM Developer
@lidderupk
IBM Developer

Step 15a - view the model

@lidderupk
IBM Developer

Step 15b - view the model, another way

@lidderupk
IBM Developer

Step 16 - add a new deployment

@lidderupk
IBM Developer

1

2

Step 17 - ensure that deployment is successful with ready status

@lidderupk
IBM Developer

Step 18a - implementation / test the deployed model

@lidderupk
IBM Developer
{"input_data":[{
        "fields": ["CRIM","ZN","INDUS","CHAS","NOX","RM","AGE","DIS","RAD","TAX","PTRATIO","B","LSTAT"],
        "values": [[0.00632,18,2.31,0,0.538,6.575,65.2,4.09,1,296,15.3,396.9,4.98]]
}]}

Step 18b - implementation / test the deployed model

@lidderupk
IBM Developer

AutoAI - Behind the scenes

Data pre-processing

  • analyze, clean and prepare raw data for ML
  • automatically detects and categorizes features based on data type
  • missing value imputation
  • feature encoding
  • feature scaling

Automated model selection

  • test and rank candidate estimators
  • select the best performing estimator with the ranking choice made by the user

Automated Feature Engineering

  • transform raw data into combination of features that best fit the model

Hyperparameter Optimization

  • refine the best performing model
@lidderupk
IBM Developer

AutoAI - Supported Estimators

Watson Machine Learning

WML - Supported Frameworks as of 06.21.19

@lidderupk
IBM Developer

IBM Watson Machine Learning 

@lidderupk
IBM Developer

IBM Watson Machine Learning Client 

@lidderupk
IBM Developer

http://wml-api-pyclient.mybluemix.net/index.html

WML - create scikit-learn linear regression model

@lidderupk
IBM Developer
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score

boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)

# Create a new Linear Regression Model
LR_model = LinearRegression()

# Train the model
LR_model.fit(X_train, y_train)

# store actual and predited data to draw chart
predicted = LR_model.predict(X_test)
actual = y_test


# The coefficients
print('Coefficients: \n', LR_model.coef_)
# The mean squared error
print("Mean squared error: %.2f"
      % mean_squared_error(actual, predicted))
# Explained variance score: 1 is perfect prediction
print('Variance score: %.2f' % r2_score(actual, predicted))
Output

👉🏽

WML - evaluation metrics

@lidderupk
IBM Developer

AutoAI

Notebook

WML - get Machine Learning service credentials

@lidderupk
IBM Developer

WML - get Machine Learning service credentials

@lidderupk
IBM Developer

WML - save scikit-learn linear regression model

@lidderupk
IBM Developer
# we will use WML to work with IBM Machine Learning Service
from watson_machine_learning_client import WatsonMachineLearningAPIClient

# Grab your credentials from the Watson Service section in Watson Studio or IBM Cloud Dashboard
wml_credentials = {
}

# Instantiate WatsonMachineLearningAPIClient
from watson_machine_learning_client import WatsonMachineLearningAPIClient
client = WatsonMachineLearningAPIClient( wml_credentials )

# 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)

WML - deploy scikit-learn linear regression model

@lidderupk
IBM Developer
import json

# 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")

#get the scoring endpoint
scoring_endpoint = client.deployments.get_scoring_url(model_deployed)
print(scoring_endpoint)

#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))

WML - deploy scikit-learn linear regression model

@lidderupk
IBM Developer

WML - try it out on your own ! Step1 - Sign into IBM Cloud

@lidderupk
IBM Developer
@lidderupk
IBM Developer

Step2 - create a new notebook from URL

Grab the FULL URL from : http://bit.ly/boston-house-notebook

@lidderupk
IBM Developer

Step3 - paste your WML credentials and run each cell!

Grab the FULL URL from : 

http://bit.ly/boston-house-notebook

IBM Code Patterns

@lidderupk
IBM Developer

Thank you

 

Let's chat !

@lidderupk
IBM Developer

Upkar Lidder, IBM

 

@lidderupk

https://github.com/lidderupk/

ulidder@us.ibm.com

@lidderupk
IBM Developer
Made with Slides.com