Upkar Lidder
http://bit.ly/ibm-hive-ml
https://slides.com/upkar/ai-ml-on-ibm-cloud
> ulidder@us.ibm.com > @lidderupk > upkar.dev
@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.
@lidderupk
IBM Developer
@lidderupk
IBM Developer
Natural Language Processing
Visual Recognition
@lidderupk
IBM Developer
@lidderupk
IBM Developer
http://bit.ly/california-houses-csv
1. longitude: A measure of how far west a house is; a higher value is farther west
2. latitude: A measure of how far north a house is; a higher value is farther north
3. housingMedianAge: Median age of a house within a block; a lower number is a newer building
4. totalRooms: Total number of rooms within a block
5. totalBedrooms: Total number of bedrooms within a block
6. population: Total number of people residing within a block
7. households: Total number of households, a group of people residing within a home unit, for a block
8. medianIncome: Median income for households within a block of houses (measured in tens of thousands of US Dollars)
9. oceanProximity: Location of the house w.r.t ocean/sea
10. medianHouseValue: Median house value for households within a block (measured in US Dollars)
@lidderupk
IBM Developer
@lidderupk
IBM Developer
To help simplify an AI lifecycle management, AutoAI automates:
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
Successfully Create, Store and Deploy a Linear Regression Model on IBM Cloud using Watson Studio and Watson Machine Learning Services.
@lidderupk
IBM Developer
Median House Price
Property Tax
#sqft
@lidderupk
IBM Developer
#sqft
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
http://bit.ly/boston-house-csv
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
1
2
@lidderupk
IBM Developer
@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]]
}]}
@lidderupk
IBM Developer
Data pre-processing
Automated model selection
Automated Feature Engineering
Hyperparameter Optimization
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@lidderupk
IBM Developer
http://wml-api-pyclient.mybluemix.net/index.html
@lidderupk
IBM Developer
#import libraries
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
import pandas as pd
import numpy as np
#read the dataset
housing = df_data_1
#remove empty rows. Ideally we would populate with a reasonable value (median, mean)
housing = housing.dropna(axis=0)
train_set, test_set = train_test_split(housing, test_size=0.2, random_state=42)
housing_labels = train_set["median_house_value"].copy()
X_test = test_set.drop("median_house_value", axis=1)
y_test = test_set["median_house_value"].copy()
# use one hot encoding on the categorial columns
cat_attribs = ["ocean_proximity"]
full_pipeline = ColumnTransformer([
("cat", OneHotEncoder(), cat_attribs),
])
housing_prepared = full_pipeline.fit_transform(train_set)
lin_reg = LinearRegression()
lin_reg.fit(housing_prepared, housing_labels)
#let's make some predictions!
some_data = housing.iloc[:5]
some_labels = housing_labels.iloc[:5]
some_data_prepared = full_pipeline.transform(some_data)
print("Predictions:", lin_reg.predict(some_data_prepared))
#evaluate on the test data
X_test_prepared = full_pipeline.transform(X_test)
final_predictions = lin_reg.predict(X_test_prepared)
final_mse = mean_squared_error(y_test, final_predictions)
final_rmse = np.sqrt(final_mse)
print('Final rmse: ', final_rmse)
@lidderupk
IBM Developer
housing_prepared = full_pipeline.fit_transform(train_set)
lin_reg = LinearRegression()
lin_reg.fit(housing_prepared, housing_labels)
#let's make some predictions!
some_data = housing.iloc[:5]
some_labels = housing_labels.iloc[:5]
some_data_prepared = full_pipeline.transform(some_data)
print("Predictions:", lin_reg.predict(some_data_prepared))
#evaluate on the test data
X_test_prepared = full_pipeline.transform(X_test)
final_predictions = lin_reg.predict(X_test_prepared)
final_mse = mean_squared_error(y_test, final_predictions)
final_rmse = np.sqrt(final_mse)
print('Final rmse: ', final_rmse)
Predictions: [257941.45656895 257941.45656895 257941.45656895 257941.45656895 257941.45656895]
Final rmse: 101502.3371732095
@lidderupk
IBM Developer
@lidderupk
IBM Developer
@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)
@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))
@lidderupk
IBM Developer
@lidderupk
IBM Developer
Upkar Lidder, IBM
@lidderupk
https://github.com/lidderupk/
ulidder@us.ibm.com
@lidderupk
IBM Developer
@lidderupk
IBM Developer