59
Real-Time Decisions Using ML on the Google Cloud Platform Przemysław Pastuszka & Carlos Garcia QCon London 7th March 2018

Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Real-Time Decisions Using ML on the Google Cloud Platform

Przemysław Pastuszka & Carlos GarciaQCon London7th March 2018

Page 2: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

How many of you are interested in machine

learning?

Page 3: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

but… how many of you are running real-time machine

learning in production?

Page 4: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Who is Ocado?

Ocado is the world’s largest dedicated

online grocery retailer

We have 645,000 active shoppers

And 49,000 SKUs in our webshop

Three highly-automated fulfilment centres

263,000 orders a week ‘picked’

3 million routing calculations per second

Page 5: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000
Page 6: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

What Ocado Technology does

(1) Cloud and AI(2) Automation and robotics(3) Big Data (4) Web and app development(5) IoT

Page 7: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Fraud: An ML journey

Page 8: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000
Page 9: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000
Page 10: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

But then… what is fraud?

• Mainly chargebacks

• Other types of fraud?

• Learn from the actual outcome

Page 11: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Do I really need to do any ML?

Page 12: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Know your target

• Do you need ML?

• What do you want to predict?

• How good are you at predicting that?

Page 13: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Cost of mistakes

• False positives and false negatives

• How expensive are they?

Page 14: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Start with heuristics

• Ask domain experts

• Derive rules from expert knowledge• “If more than 80% of order is alcohol, then classify as risky”

Page 15: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Heuristics are not enough

Page 16: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Motivations for Machine Learning

Data-driven

Page 17: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Motivations for Machine Learning

Data-driven Fraudsters learn

Page 18: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Motivations for Machine Learning

Data-driven Fraudsters learn

Customer patterns

Page 19: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Motivations for Machine Learning

Data-driven Fraudsters learn

Business changesCustomer patterns

Page 20: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Challenges

• Fraud (human) agents

• ML is affected by human decisions

• Unbalanced classes (fraud / not-fraud)

Page 21: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

What ML model do you choose?

Page 22: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

“With great power there must also come… great

responsibility”Spider-Man

Page 23: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Criteria

Online vs batch predictions

Page 24: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Criteria

Online vs batch predictions

Explainable predictions

Page 25: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Challenge your explanations

“Why should I trust you?”2016, M. Tulio, S. Singh, C. Guestrin

Page 26: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Criteria

Online vs batch predictions

Explainable predictions

Programming language

Page 27: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Criteria

Online vs batch predictions

Explainable predictions

Cloud vs on-premiseProgramming

language

Page 28: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Our ML choice

Page 29: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Criteria

Online vs batch predictions

Explainable predictions

Cloud vs on-premiseProgramming

language

online preferable

cloudPython /

Java

Page 30: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Machine Learning

EngineµService

Cloud Storage

Model

Page 31: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000
Page 32: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Interesting alternatives

Amazon SageMaker

Page 33: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Interesting alternatives

Amazon SageMaker

Google CloudMachine Learning

Engine

Page 34: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Problem #1Not fast enough

Page 35: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Data exploration cycle

State the hypothesis

Act

Validate

03

01 02

Page 36: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Big Query

Validate your hypothesis - fast!

Page 37: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000
Page 38: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000
Page 39: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Problem #2Data delivered too late

Page 40: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

µService

µService

µService

µService

Amazon Web Services

Google Cloud Platform

Big QueryKinesis

Data Flow

Apache Beam

+

Page 41: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

List<String> strings = ...strings.stream().collect( Collectors.groupingBy(

word -> word.charAt(0), Collectors.counting()));

PCollection<String> pipeline = ...pipeline .apply(MapElements.via(row -> KV.of(word.charAt(0), word))) .apply(GroupByKey.create()) .apply(Count.perKey())

Page 42: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Apache Beam

ApacheApex

ApacheFlink

ApacheSpark

Google Dataflow

ApacheGearpump

Page 43: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Problem #3Missing data

Page 44: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Missing data

Page 45: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Capture every change to the business state

Page 46: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Training

Page 47: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000
Page 48: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

train(C1, … CN, O1, … ON, Y) = model

C1, … CN, O1, … ON - customer and order featuresC1- Average basket size for the customerO1- % of alcoholic items in current order...

Y - Fraud or not fraud

Page 49: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Machine Learning

Engine

Model

FeaturesEventsC1…, O1, …

Page 50: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Machine Learning

Engine

Model

FeaturesEventsSQL

Apache Airflow

C1…, O1, …

Page 51: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Serving predictions

Page 52: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

train(C1, … CN, O1, … ON, Y) = modelmodel(C1, … CN, O1, … ON) = prediction

C1, … CN, O1, … ON - customer and order featuresC1- Average basket size for the customerO1- % of alcoholic items in current order...

Y - Fraud or not fraudprediction - Probability of current order being fraudulent

Page 53: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Model

µService

O1, … ON Machine Learning

Engine

Page 54: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Model

FeaturesEventsSQL

Apache Airflow

µService

Datastore

Custom App

ID: C1…

ID, O1, … C1…, O1, … Machine Learning

Engine

Page 55: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Model

FeaturesEventsSQL

Apache Airflow

µService

Datastore

Custom App

ID: C1…

ID, O1, … C1…, O1, … Machine Learning

Engine

Training

Serving

C1…, O1, …

Page 56: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Architecting for the future

Page 57: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Machine Learning

Engine

Model

FeaturesEventsSQL

Apache AirflowTraining

µService

DatastoreServing

Custom App

Page 58: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Know your target

Keep It Simple

Choose your model wisely

Google Cloud ML Engine for Neural Nets

Have data and tools ready

BigQuery is king

Unified architecture for training and serving predictions

Page 59: Google Cloud Platform Using ML on the Real-Time Decisions · Who is Ocado? Ocado is the world’s largest dedicated online grocery retailer We have 645,000 active shoppers And 49,000

Thank you!