SlideShare a Scribd company logo
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
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
Watson Studio & Watson Machine LearningWatson Studio & Watson Machine Learning
@lidderupkIBM Developer
Watson StudioWatson Studio
IBM Watson Studio IBM Watson Studio 
@lidderupkIBM Developer
IBM Watson Studio IBM Watson Studio 
@lidderupkIBM Developer
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.
Question -Question - predict median house price for Boston areapredict median house price for Boston area
@lidderupkIBM Developer
Linear regressionLinear regression - Simple- Simple
@lidderupkIBM Developer
Median
HousePrice
Another Variable
Y = ⍺ + βx
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 !
Step 1 -Step 1 - sign up/ log into IBM Cloudsign up/ log into IBM Cloud
@lidderupkIBM Developer
http://bit.ly/waston-ml-sign
Step 2 -Step 2 - locate Watson Studio in Cataloglocate Watson Studio in Catalog
@lidderupkIBM Developer
Step 3 -Step 3 - create Watson Studio instancecreate Watson Studio instance
@lidderupkIBM Developer
Step 4 -Step 4 - launch Watson Studiolaunch Watson Studio
@lidderupkIBM Developer
Step 5 -Step 5 - create a new projectcreate a new project
@lidderupkIBM Developer
Step 6 -Step 6 - pick Data Science starterpick Data Science starter
@lidderupkIBM Developer
Step 7 -Step 7 - give the project a name and assign COSgive the project a name and assign COS
@lidderupkIBM Developer
Step 8 -Step 8 - open asset tabopen asset tab
@lidderupkIBM Developer
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
Step 10 -Step 10 - add Machine Learning model to the projectadd Machine Learning model to the project
@lidderupkIBM Developer
Step 11 - associate a ML instanceStep 11 - associate a ML instance
@lidderupkIBM Developer
Step 12a -Step 12a - create ML instance if you don't have onecreate ML instance if you don't have one
@lidderupkIBM Developer
Step 12b -Step 12b - create a new lite ML instancecreate a new lite ML instance
@lidderupkIBM Developer
@lidderupkIBM Developer
Step 12c -Step 12c - create a new lite ML instancecreate a new lite ML instance
Step 12d -Step 12d - reload the ML service sectionreload the ML service section
@lidderupkIBM Developer
Step 13 -Step 13 - pick new service and create a model manuallypick new service and create a model manually
@lidderupkIBM Developer
Step 14 -Step 14 - pick the Boston data file aspick the Boston data file as data assetdata asset
@lidderupkIBM Developer
@lidderupkIBM Developer
Step 15 -Step 15 - pick target, input features and model typepick target, input features and model type
@lidderupkIBM Developer
Step 16 -Step 16 - add estimator(s)add estimator(s)
@lidderupkIBM Developer
Step 17 -Step 17 - change hyperparameters (optional)change hyperparameters (optional)
@lidderupkIBM Developer
Step 18 -Step 18 - save/store the trained model on IBM Cloudsave/store the trained model on IBM Cloud
@lidderupkIBM Developer
Step 19 -Step 19 - add a new deploymentadd a new deployment
@lidderupkIBM Developer
1
2
Step 20 -Step 20 - ensure that deployment is successfulensure that deployment is successful
@lidderupkIBM Developer
Step 21a -Step 21a - implementation / test the deployed modelimplementation / test the deployed model
@lidderupkIBM Developer
{
"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, 66, 4.09, 1, 296, 15.3, 396.9, 4.99]
]
}
1
2
3
4
5
6
Step 21b -Step 21b - implementation / test the deployed modelimplementation / test the deployed model
@lidderupkIBM Developer
Watson Studio - Binary ClassificationWatson Studio - Binary Classification
@lidderupkIBM Developer
Watson Studio - Multiclass ClassificationWatson Studio - Multiclass Classification
@lidderupkIBM Developer
Watson Studio - RegressionWatson Studio - Regression
Watson Machine LearningWatson Machine Learning
WML -WML - Supported Frameworks as of 06.21.19Supported Frameworks as of 06.21.19
@lidderupkIBM Developer
IBM Watson Machine Learning IBM Watson Machine Learning 
@lidderupkIBM Developer
IBM Watson Machine Learning Client IBM Watson Machine Learning Client 
@lidderupkIBM Developer http://wml-api-pyclient.mybluemix.net/index.html
WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model
@lidderupkIBM 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
1
2
3
4
5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
Output
WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model
@lidderupkIBM 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
1
2
3
4
5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
7
8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
Output
WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model
@lidderupkIBM 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
1
2
3
4
5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
7
8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# Create a new Linear Regression Model
LR_model = LinearRegression()
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
10
11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
Output
WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model
@lidderupkIBM 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
1
2
3
4
5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
7
8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# Create a new Linear Regression Model
LR_model = LinearRegression()
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
10
11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# Train the model
LR_model.fit(X_train, y_train)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
13
14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
Output
WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model
@lidderupkIBM 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
1
2
3
4
5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
7
8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# Create a new Linear Regression Model
LR_model = LinearRegression()
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
10
11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# Train the model
LR_model.fit(X_train, y_train)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
13
14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# store actual and predited data to draw chart
predicted = LR_model.predict(X_test)
actual = y_test
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
16
17
18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
Output
WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model
@lidderupkIBM 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
1
2
3
4
5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
7
8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# Create a new Linear Regression Model
LR_model = LinearRegression()
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
10
11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# Train the model
LR_model.fit(X_train, y_train)
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
13
14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# store actual and predited data to draw chart
predicted = LR_model.predict(X_test)
actual = y_test
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
16
17
18
19
20
# The coefficients21
print('Coefficients: n', LR_model.coef_)22
# The mean squared error23
print("Mean squared error: %.2f"24
% mean_squared_error(actual, predicted))25
# Explained variance score: 1 is perfect prediction26
print('Variance score: %.2f' % r2_score(actual, predicted))27
# 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))
from sklearn.linear_model import LinearRegression1
from sklearn.datasets import load_boston2
import matplotlib.pyplot as plt3
from sklearn.model_selection import train_test_split4
from sklearn.metrics import mean_squared_error, r2_score5
6
boston = load_boston()7
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8
9
# Create a new Linear Regression Model10
LR_model = LinearRegression()11
12
# Train the model13
LR_model.fit(X_train, y_train)14
15
# store actual and predited data to draw chart16
predicted = LR_model.predict(X_test)17
actual = y_test18
19
20
21
22
23
24
25
26
27
Output
WML -WML - evaluation metricsevaluation metrics
@lidderupkIBM Developer
WML -WML - get Machine Learning service credentialsget Machine Learning service credentials
@lidderupkIBM Developer
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
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
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
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
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
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
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
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
WML -WML - deploy scikit-learn linear regression modeldeploy scikit-learn linear regression model
@lidderupkIBM Developer
WML -WML - try it out on your own !try it out on your own !
@lidderupkIBM Developer
http://bit.ly/waston-ml-sign
@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
Thank youThank you
 
Let's chat !Let's chat !
@lidderupkIBM Developer
Upkar Lidder, IBM
 
@lidderupk
https://github.com/lidderupk/
ulidder@us.ibm.com

More Related Content

What's hot

What's hot (20)

Artificial Intelligence Overview PowerPoint Presentation Slides
Artificial Intelligence Overview PowerPoint Presentation Slides Artificial Intelligence Overview PowerPoint Presentation Slides
Artificial Intelligence Overview PowerPoint Presentation Slides
 
Using Generative AI
Using Generative AIUsing Generative AI
Using Generative AI
 
Regulating Generative AI - LLMOps pipelines with Transparency
Regulating Generative AI - LLMOps pipelines with TransparencyRegulating Generative AI - LLMOps pipelines with Transparency
Regulating Generative AI - LLMOps pipelines with Transparency
 
AI and ML Series - Introduction to Generative AI and LLMs - Session 1
AI and ML Series - Introduction to Generative AI and LLMs - Session 1AI and ML Series - Introduction to Generative AI and LLMs - Session 1
AI and ML Series - Introduction to Generative AI and LLMs - Session 1
 
Overview on Azure Machine Learning
Overview on Azure Machine LearningOverview on Azure Machine Learning
Overview on Azure Machine Learning
 
Introduction to AI/ML with AWS
Introduction to AI/ML with AWSIntroduction to AI/ML with AWS
Introduction to AI/ML with AWS
 
Discover AI with Microsoft Azure
Discover AI with Microsoft AzureDiscover AI with Microsoft Azure
Discover AI with Microsoft Azure
 
Unlocking the Power of Generative AI An Executive's Guide.pdf
Unlocking the Power of Generative AI An Executive's Guide.pdfUnlocking the Power of Generative AI An Executive's Guide.pdf
Unlocking the Power of Generative AI An Executive's Guide.pdf
 
Unleashing the Power of OpenAI GPT-3 in FME Data Integration Workflows
Unleashing the Power of OpenAI GPT-3 in FME Data Integration WorkflowsUnleashing the Power of OpenAI GPT-3 in FME Data Integration Workflows
Unleashing the Power of OpenAI GPT-3 in FME Data Integration Workflows
 
Architect’s Open-Source Guide for a Data Mesh Architecture
Architect’s Open-Source Guide for a Data Mesh ArchitectureArchitect’s Open-Source Guide for a Data Mesh Architecture
Architect’s Open-Source Guide for a Data Mesh Architecture
 
ChatGPT Deck.pptx
ChatGPT Deck.pptxChatGPT Deck.pptx
ChatGPT Deck.pptx
 
Ml ops on AWS
Ml ops on AWSMl ops on AWS
Ml ops on AWS
 
IBM Watson Overview
IBM Watson OverviewIBM Watson Overview
IBM Watson Overview
 
[Giovanni Galloro] How to use machine learning on Google Cloud Platform
[Giovanni Galloro] How to use machine learning on Google Cloud Platform[Giovanni Galloro] How to use machine learning on Google Cloud Platform
[Giovanni Galloro] How to use machine learning on Google Cloud Platform
 
Introduction to snowflake
Introduction to snowflakeIntroduction to snowflake
Introduction to snowflake
 
Databricks Overview for MLOps
Databricks Overview for MLOpsDatabricks Overview for MLOps
Databricks Overview for MLOps
 
Snowflake Overview
Snowflake OverviewSnowflake Overview
Snowflake Overview
 
Application Portfolio Migration
Application Portfolio MigrationApplication Portfolio Migration
Application Portfolio Migration
 
Artificial Intelligence Machine Learning Deep Learning Ppt Powerpoint Present...
Artificial Intelligence Machine Learning Deep Learning Ppt Powerpoint Present...Artificial Intelligence Machine Learning Deep Learning Ppt Powerpoint Present...
Artificial Intelligence Machine Learning Deep Learning Ppt Powerpoint Present...
 
An Introduction to Generative AI
An Introduction  to Generative AIAn Introduction  to Generative AI
An Introduction to Generative AI
 

Similar to Machine Learning on IBM Watson Studio

Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
ccis224477
 
Getting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiGetting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viii
Amit Sharma
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
lhkslkdh89009
 

Similar to Machine Learning on IBM Watson Studio (20)

PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
A case study in using ibm watson studio machine learning services ibm devel...
A case study in using ibm watson studio machine learning services   ibm devel...A case study in using ibm watson studio machine learning services   ibm devel...
A case study in using ibm watson studio machine learning services ibm devel...
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
 
Cis 247 all i labs
Cis 247 all i labsCis 247 all i labs
Cis 247 all i labs
 
Call For Code: 시각인식을 활용한 피해상황 파악하기 by 맹개발
Call For Code: 시각인식을 활용한 피해상황 파악하기 by 맹개발Call For Code: 시각인식을 활용한 피해상황 파악하기 by 맹개발
Call For Code: 시각인식을 활용한 피해상황 파악하기 by 맹개발
 
Yufeng Guo | Coding the 7 steps of machine learning | Codemotion Madrid 2018
Yufeng Guo |  Coding the 7 steps of machine learning | Codemotion Madrid 2018 Yufeng Guo |  Coding the 7 steps of machine learning | Codemotion Madrid 2018
Yufeng Guo | Coding the 7 steps of machine learning | Codemotion Madrid 2018
 
What’s New in Spring Data MongoDB
What’s New in Spring Data MongoDBWhat’s New in Spring Data MongoDB
What’s New in Spring Data MongoDB
 
QSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & AQSDA2022: Qlik Sense Data Architect | Q & A
QSDA2022: Qlik Sense Data Architect | Q & A
 
Enterprise AI using DB2
Enterprise AI using DB2Enterprise AI using DB2
Enterprise AI using DB2
 
Getting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiGetting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viii
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
Enterprise AI by using IBM DB2
Enterprise AI by using IBM DB2Enterprise AI by using IBM DB2
Enterprise AI by using IBM DB2
 
Weather data meets ibm cloud. part 4 analysis and visualization of weather ...
Weather data meets ibm cloud. part 4   analysis and visualization of weather ...Weather data meets ibm cloud. part 4   analysis and visualization of weather ...
Weather data meets ibm cloud. part 4 analysis and visualization of weather ...
 
Web Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe KaplanWeb Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe Kaplan
 
AWS DevDay Vienna - Automating building blocks choices you will face with con...
AWS DevDay Vienna - Automating building blocks choices you will face with con...AWS DevDay Vienna - Automating building blocks choices you will face with con...
AWS DevDay Vienna - Automating building blocks choices you will face with con...
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
 
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOpsPVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
PVS-Studio Is Now in Chocolatey: Checking Chocolatey under Azure DevOps
 
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuffBig Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
 
PVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOpsPVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOps
 

Recently uploaded

Recently uploaded (20)

How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 

Machine Learning on IBM Watson Studio

  • 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
  • 5. IBM Watson Studio IBM Watson Studio  @lidderupkIBM Developer
  • 6. IBM Watson Studio IBM Watson Studio  @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
  • 9. Linear regressionLinear regression - Simple- Simple @lidderupkIBM Developer Median HousePrice Another Variable Y = ⍺ + βx
  • 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
  • 14. Step 4 -Step 4 - launch Watson Studiolaunch Watson Studio @lidderupkIBM Developer
  • 15. Step 5 -Step 5 - create a new projectcreate a new project @lidderupkIBM Developer
  • 16. Step 6 -Step 6 - pick Data Science starterpick Data Science starter @lidderupkIBM Developer
  • 17. Step 7 -Step 7 - give the project a name and assign COSgive the project a name and assign COS @lidderupkIBM Developer
  • 18. Step 8 -Step 8 - open asset tabopen asset tab @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
  • 24. @lidderupkIBM Developer Step 12c -Step 12c - create a new lite ML instancecreate a new lite ML instance
  • 25. Step 12d -Step 12d - reload the ML service sectionreload the ML service section @lidderupkIBM Developer
  • 26. Step 13 -Step 13 - pick new service and create a model manuallypick new service and create a model manually @lidderupkIBM Developer
  • 27. Step 14 -Step 14 - pick the Boston data file aspick the Boston data file as data assetdata asset @lidderupkIBM Developer
  • 28. @lidderupkIBM Developer Step 15 -Step 15 - pick target, input features and model typepick target, input features and model type
  • 29. @lidderupkIBM Developer Step 16 -Step 16 - add estimator(s)add estimator(s)
  • 30. @lidderupkIBM Developer Step 17 -Step 17 - change hyperparameters (optional)change hyperparameters (optional)
  • 31. @lidderupkIBM Developer Step 18 -Step 18 - save/store the trained model on IBM Cloudsave/store the trained model on IBM Cloud
  • 32. @lidderupkIBM Developer Step 19 -Step 19 - add a new deploymentadd a new deployment
  • 33. @lidderupkIBM Developer 1 2 Step 20 -Step 20 - ensure that deployment is successfulensure that deployment is successful
  • 34. @lidderupkIBM Developer Step 21a -Step 21a - implementation / test the deployed modelimplementation / test the deployed model
  • 35. @lidderupkIBM Developer { "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, 66, 4.09, 1, 296, 15.3, 396.9, 4.99] ] } 1 2 3 4 5 6 Step 21b -Step 21b - implementation / test the deployed modelimplementation / test the deployed model
  • 36. @lidderupkIBM Developer Watson Studio - Binary ClassificationWatson Studio - Binary Classification
  • 37. @lidderupkIBM Developer Watson Studio - Multiclass ClassificationWatson Studio - Multiclass Classification
  • 38. @lidderupkIBM Developer Watson Studio - RegressionWatson Studio - Regression
  • 39. Watson Machine LearningWatson Machine Learning
  • 40. WML -WML - Supported Frameworks as of 06.21.19Supported Frameworks as of 06.21.19 @lidderupkIBM Developer
  • 41. IBM Watson Machine Learning IBM Watson Machine Learning  @lidderupkIBM Developer
  • 42. IBM Watson Machine Learning Client IBM Watson Machine Learning Client  @lidderupkIBM Developer http://wml-api-pyclient.mybluemix.net/index.html
  • 43. WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model @lidderupkIBM 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 1 2 3 4 5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 Output
  • 44. WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model @lidderupkIBM 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 1 2 3 4 5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 boston = load_boston() X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 7 8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 Output
  • 45. WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model @lidderupkIBM 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 1 2 3 4 5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 boston = load_boston() X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 7 8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # Create a new Linear Regression Model LR_model = LinearRegression() from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 10 11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 Output
  • 46. WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model @lidderupkIBM 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 1 2 3 4 5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 boston = load_boston() X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 7 8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # Create a new Linear Regression Model LR_model = LinearRegression() from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 10 11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # Train the model LR_model.fit(X_train, y_train) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 13 14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 Output
  • 47. WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model @lidderupkIBM 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 1 2 3 4 5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 boston = load_boston() X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 7 8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # Create a new Linear Regression Model LR_model = LinearRegression() from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 10 11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # Train the model LR_model.fit(X_train, y_train) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 13 14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # store actual and predited data to draw chart predicted = LR_model.predict(X_test) actual = y_test from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 16 17 18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 Output
  • 48. WML -WML - create scikit-learn linear regression modelcreate scikit-learn linear regression model @lidderupkIBM 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 1 2 3 4 5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 boston = load_boston() X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 7 8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # Create a new Linear Regression Model LR_model = LinearRegression() from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 10 11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # Train the model LR_model.fit(X_train, y_train) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 13 14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # store actual and predited data to draw chart predicted = LR_model.predict(X_test) actual = y_test from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 16 17 18 19 20 # The coefficients21 print('Coefficients: n', LR_model.coef_)22 # The mean squared error23 print("Mean squared error: %.2f"24 % mean_squared_error(actual, predicted))25 # Explained variance score: 1 is perfect prediction26 print('Variance score: %.2f' % r2_score(actual, predicted))27 # 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)) from sklearn.linear_model import LinearRegression1 from sklearn.datasets import load_boston2 import matplotlib.pyplot as plt3 from sklearn.model_selection import train_test_split4 from sklearn.metrics import mean_squared_error, r2_score5 6 boston = load_boston()7 X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target)8 9 # Create a new Linear Regression Model10 LR_model = LinearRegression()11 12 # Train the model13 LR_model.fit(X_train, y_train)14 15 # store actual and predited data to draw chart16 predicted = LR_model.predict(X_test)17 actual = y_test18 19 20 21 22 23 24 25 26 27 Output
  • 49. WML -WML - evaluation metricsevaluation metrics @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