machine learning introduction - indico · esa unclassified - for official use jose martinez heras |...

91
ESA UNCLASSIFIED - For Official Use Machine Learning Introduction Jose Martinez Heras 16/04/2019

Upload: others

Post on 11-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use

Machine Learning Introduction

Jose Martinez Heras

16/04/2019

Page 2: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 2

About

• José Martínez Heras

• Computer Scientist

• Spanish

Page 3: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 3

Machine Learning Lectures at ESOC

https://github.com/jmartinezheras/2018-MachineLearning-Lectures-ESA

Page 4: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 4

Objectives for this session

• What Machine Learning can / cannot do

• Examples in Space and other domains

• How it works

• Key Concepts & Best Practices

• Understand how some techniques work

• Hands-On session: predict Mars Express thermal power consumption

Page 5: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 5

Artificial Intelligence

Reasoning

Knowledge

Planning

Machine Learning

Natural Language Processing

Perception

Move & manipulate

objects

Page 6: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 6

Artificial Intelligence

Reasoning

Knowledge

Planning

Machine Learning

Natural Language Processing

Perception

Move & manipulate

objects

Page 7: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 7

Artificial Intelligence

Reasoning

Knowledge

Planning

Machine Learning

Natural Language Processing

Perception

Move & manipulate

objects

Page 8: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 8

What’s Machine Learning?

• “The field of study that gives computers the ability to learn without being

explicitly programmed” [Artur Samuel, 1959]

• “A computer program is said to learn from experience E with respect to some

task T and some performance measure P, if its performance on T, as measured

by P, improves with experience E” [Tom Mitchell, 1997]

• The science (and art) of programming computers so that they can learn

from data [Aurélien Géron, 2017]

Page 9: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 9

How is Machine Learning different from programming

DataProgram

Perform task

Results DataModel

Perform task

Results

Data

ML

Learning

ModelResults

Requirements Program

Only for some tasks

Page 10: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10

Which tasks can Machine Learning perform?

- Let’s see some examples

Spam Filter Recommendation Engine

Page 11: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 11

Which tasks can Machine Learning perform?

Real Estate

Predict at which price a property will be sold

Page 12: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 12

Which tasks can Machine Learning perform?

Advertising

Predict which ads you are more likely to click on

Page 13: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 13

Which tasks can Machine Learning perform?

Image Classification

Page 14: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 14

Which tasks can Machine Learning perform?

Self-driving cars

Page 15: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 15

Which tasks can Machine Learning perform?

Speech Recognition & Synthesis

Page 16: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 16

Which tasks can Machine Learning perform?

Language Translation

Page 17: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 17

Which tasks can Machine Learning perform?

Playing Games

Page 18: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 18

Some examples in Space Operations

Dr.MUST diagnostics: find the cause of an anomaly

VEX attitude errors because of Aspera payload activation

Page 19: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 19

Some examples in Space Operations

Novelty Detection: a novel behaviour is often the signature of an

anomaly in the way to happen

OOL

Unusual behaviour

Potential anomaly

XMM Tank1 Ext temperature

Page 20: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 20

Some examples in Space Operations

[MEX] Predict Thermal Power Consumption: Machine Learning competition

Page 21: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 21

Some examples in Space Operations

[Integral] Radiation Belts entry / exit times prediction to increase science return

Page 22: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 22

Some examples in Space Operations

[esa.int] Predict which articles will receive

a high number of views

High: Rosetta, comet, surface, lander, image, crater, mars, stars, galaxy, black holes

Low: ESA, company, technology

Page 23: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 23

Considerations on using Machine Learning

• There must be a pattern in the input –

output relationship (lottery winning

numbers cannot be predicted with ML)

• There must be enough data to

discover this pattern

• It’s difficult to formulate a

mathematical expression (otherwise

we will just use this formula instead)

DataModel

Perform task

Results

Data

ML

Learning

ModelResults

Page 24: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 24

How Machine Learning Learns?

• Different Machine Learning techniques

for different kinds of tasks

• Learning is finding which model’s

parameters represent best the input –

output mapping

DataModel

Perform task

Results

Data

ML

Learning

ModelResults

Page 25: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 25

How Machine Learning Learns?

• Linear Regression example:

• Model: f(x) = mx + b

• Model’s parameters: m, b

• Parameter values: m=1, b=0

• Learning is finding which values of ‘m’

and ‘b’ fit the data best (e.g.

minimizes the prediction error)

DataModel

Perform task

Results

Data

ML

Learning

ModelResults

Page 26: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 26

How Machine Learning Learns?

Find the model parameters values that minimize the error

Page 27: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 27

How Machine Learning Learns?

m = 0.1014b = 1.2258

Find the model parameters values that minimize the error

Page 28: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 28

How Machine Learning Learns? – some models

Polynomials: ax + bx2 + … + c

Support Vector Machines (SVM): Vectors

Decision trees: which nodes, which decisions

Page 29: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 29

How Machine Learning Learns? – some models

Neural Networks / Deep Learning: weights

Page 30: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 30

Types of Learning

Depending on the level of supervision …

• Supervised

• Unsupervised

• Semi-supervised

• Reinforcement Learning

Page 31: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 31

Types of Learning

• Supervised

• Supervision: we can tell for every case what the correct answer was

• Example: predict the thermal power consumption

FocusPredict the future

Page 32: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 32

Types of Learning

• Unsupervised

• Supervision: there is no right answer, we are looking for insights

• Example: market basket analysis for supermarkets

FocusUnderstand the past

Page 33: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 33

Types of Learning

• Semi-supervised

• Supervision: we can tell the correct output for a limited number of cases

• Example: characterize what a particle impact looks like in TM

Sentinel-1A: particle impact on August 23th 2016

FocusUnderstand the past

Page 34: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 34

Types of Learning

• Reinforcement Learning

• Supervision: we only know the final outcome, but not intermediate steps

• Example: playing Go

FocusFind which is the next action most likely to lead to the desired outcome

Page 35: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 35

Types of Learning

• The type of learning with most industrial applications is

Supervised Learning

(Predictive Analytics)

• Depending of what kind of data is predicted we can talk about:

• Regression

• Classification

Page 36: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 36

Regression

• Predict real numbers

Page 37: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 37

Classification

• Predict which option out of a limited set of possibilities

Spam Filter What’s in the picture

Page 38: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 38

Machine Learning Workflow

Problem Understanding

Page 39: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 39

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

• How will we measure how good the model is performing?

• Do we know already at what point it would be enough?

Page 40: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 40

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

Baseline

• How the current approach is performing against the evaluation criteria? Define a simple baseline if there is none (e.g. mean value)

• This will allow us to quantify how much Machine Learning helps and if it is worthwhile compared to simpler solutions

Page 41: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 41

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

Baseline

Prepare Data

• “Enough” data in the sense that it’s representative of the behaviour the model needs to learn

• Features: data transformations that encode your knowledge

Page 42: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 42

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

Baseline

Prepare Data Train model

• Use data / features to tune the parameters that optimize the evaluation criteria (e.g. minimise error)

Page 43: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 43

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

Baseline

Prepare Data Train model Error Analysis

More complex model

Simpler model

More data / features

Provides better problem understanding

• Understand what the model is doing: where is it right / wrong

Page 44: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 44

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

Baseline

Prepare Data Train model Error Analysis

More complex model

Simpler model

More data / features

Provides better problem understanding

ProductionTrained Model

Ready to use

Better baseline

• When we are happy with the error, we can use the trained model: new data features computation model results

• We now have a better baseline

Page 45: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 45

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

Baseline

Prepare Data Train model Error Analysis

More complex model

Simpler model

More data / features

Better problem understanding

ProductionTrained Model

Ready to use

Better baseline

Page 46: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 46

Evaluation Criteria

Typically a way to measure error.

Example:

𝑀𝑆𝐸 =1

𝑛

𝑖=1

𝑛

𝑌𝑖 − 𝑌𝑖2

Mean Squared Error

* We will see more evaluation criteria in other sessions

Page 47: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 47

Train Machine Learning Models

Let’s train 2 models to learn from this data

𝑦 = 0.1 ∗ 𝑥 + 1.25 + 0.2 ∗ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒

Page 48: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 48

Train Machine Learning Models

Mean Squared Error: 0.0372 Mean Squared Error: 0.0286

Linear Regression Polynomial Regression (degree 7)

Page 49: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 49

Generalization

Generalization: the ability of a model to perform well on new data

Page 50: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 50

Generalization

How to tell if a Machine Learning model is generalizing well when we cannot

visualize what it is doing?

?

2-dimensional data 3-dimensional data n-dimensional data

Page 51: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 51

Generalization

Split data in 2 sets

• Training Set: for training the model

• Testing Set: for evaluating the generalization of the model

* Validation set and cross-validation will be explained later

Page 52: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 52

Generalization

Data Training Data + Testing Data

The Machine Learning model now

learns from training data only

Page 53: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 53

Generalization – Error Analysis

Evaluate Performance on Training Data & Test Data

MSE Train: 0.043, MSE Test: 0.0238 MSE Train: 0.043, MSE Test: 85.113

Over-fitting

Page 54: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 54

Generalization – Error Analysis - Guidelines

Train Error Test Error What to do?

Low High • Need a simpler model• Need more data (more data samples)

* High / Low compared with the error you are willing to accept

Over-fitting

Page 55: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 55

Generalization – Error Analysis - Guidelines

Train Error Test Error What to do?

Low High • Need a simpler model• Need more data (more data samples)

High High • Need more data• Difficult to learn f(x, z) with only x. Get also z• Get more data samples

• Additional features (e.g. 1

𝑥2)

• Need a more complex model

* High / Low compared with the error you are willing to accept

Over-fitting

Under-fitting

Page 56: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 56

Generalization – Error Analysis - Guidelines

Train Error Test Error What to do?

Low High • Need a simpler model• Need more data (more data samples)

High High • Need more data• Difficult to learn f(x, z) with only x. Get also z• Get more data samples

• Additional features (e.g. 1

𝑥2)

• Need a more complex model

High Low Unusual: it could mean that the test data is too similar to the train data. Get more test data.

* High / Low compared with the error you are willing to accept

Over-fitting

Under-fitting

Page 57: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 57

Generalization – Error Analysis - Guidelines

Train Error Test Error What to do?

Low High • Need a simpler model• Need more data (more data samples)

High High • Need more data• Difficult to learn f(x, z) with only x. Get also z• Get more data samples

• Additional features (e.g. 1

𝑥2)

• Need a more complex model

High Low Unusual: it could mean that the test data is too similar to the train data. Get more test data.

Low Low You’re done! – congratulations

* High / Low compared with the error you are willing to accept

Over-fitting

Under-fitting

Page 58: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 58

Machine Learning Workflow

Problem Understanding

Evaluation Criteria

Baseline

Prepare Data Train model Error Analysis

More complex model

Simpler model

More data / features

Better problem understanding

ProductionTrained Model

Ready to use

Better baseline

Effort

Page 59: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 59

Let’s talk about Random Forests

• Decision Trees

• Ensembles

• Random Forests

Page 60: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 60

Random Forests

[MEX] Predict Thermal Power Consumption

Page 61: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 61

Random Forests

[MEX] Predict Thermal Power Consumption

[Integral] Radiation Belts

entry / exit times prediction

to increase science return

Page 62: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 62

Random Forests

[MEX] Predict Thermal Power Consumption

[Integral] Radiation Belts

entry / exit times prediction

to increase science return

Page 63: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 63

Random Forests

Random Forest = Ensemble of Decision Trees

1. Decision Trees

2. Ensembles

3. Random Forests

Page 64: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 64

Decision Trees – remember Iris example?

Iris setosa Iris versicolor Iris virginica

Knowing the sepal and petal length and width, which flower is it?

Pictures from Wikipedia contributors, "Iris flower data set," Wikipedia, The Free Encyclopedia, https://en.wikipedia.org/w/index.php?title=Iris_flower_data_set&oldid=824486644

(accessed March 5, 2018).

Page 65: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 65

Decision Trees

It also can provide probabilities

𝑝𝑠𝑒𝑡𝑜𝑠𝑎 = 1.00

Gini is a measurement of purity

𝑝𝑣𝑒𝑟𝑠𝑖𝑐𝑜𝑙𝑜𝑟 = 0.91 𝑝𝑣𝑖𝑟𝑔𝑖𝑛𝑖𝑐𝑎 = 0.98

Page 66: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 66

Decision Trees

𝐺𝑖𝑛𝑖 = 1 −

𝑘=1

𝑛

𝑝𝑐2

𝐺𝑖𝑛𝑖 = 1 −0

54

2

+49

54

2

+5

54

2

= 0.168

Gini is a measurement of purity

𝑝𝑐= probability of each class

Page 67: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 67

How do we learn to build Decision Trees?

Greedy optimization that minimizes

𝐽 𝑓, 𝑡𝑓 =𝑚𝑙𝑒𝑓𝑡

𝑚𝐺𝑖𝑛𝑖𝑙𝑒𝑓𝑡 +

𝑚𝑟𝑖𝑔ℎ𝑡

𝑚𝐺𝑖𝑛𝑖𝑟𝑖𝑔ℎ𝑡

𝑓 = which feature

𝑡𝑓 = which threshold for feature f

𝑚 = number of samples

Page 68: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 68

Features Importance

Features Importance

sepal length (cm): 0.0sepal width (cm): 0.0petal length (cm): 0.562petal width (cm): 0.438

Page 69: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 69

Decision Trees - Regression

𝑦 = 𝑥2 + 0.2 ∙ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒

Page 70: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 70

Decision Trees - Regression

𝑦 = 𝑥2 + 0.2 ∙ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒 𝐽 𝑓, 𝑡𝑓 =𝑚𝑙𝑒𝑓𝑡

𝑚𝑀𝑆𝐸𝑙𝑒𝑓𝑡 +

𝑚𝑟𝑖𝑔ℎ𝑡

𝑚𝑀𝑆𝐸𝑟𝑖𝑔ℎ𝑡

Page 71: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 71

Mean Squared Error

𝑀𝑆𝐸 =1

𝑚

𝑖=1

𝑚

𝑌𝑖 − 𝑌𝑖2

Mean Squared Error

Page 72: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 72

Decision Trees - Regression

𝑦 = 𝑥2 + 0.2 ∙ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒 𝐽 𝑓, 𝑡𝑓 =𝑚𝑙𝑒𝑓𝑡

𝑚𝑀𝑆𝐸𝑙𝑒𝑓𝑡 +

𝑚𝑟𝑖𝑔ℎ𝑡

𝑚𝑀𝑆𝐸𝑟𝑖𝑔ℎ𝑡

Page 73: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 73

Regularization in Decision Trees

overfitting tree

For this particular example. Require thateach node has ≥ 5% of the samples

Page 74: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 74

Regularization in Decision Trees

• Maximum depth

• Maximum number of leaf nodes

• Minimum number of samples at leaf nodes

• Minimum samples at node must have before it can be split

Page 75: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 75

Decision Trees don’t make assumptions

This is good because it’s not limited by a line, polynomial or any other

predefined model

𝑦 = 𝑥2 + 0.2 ∙ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒 𝑦 = sin(1.5 ∙ 𝑥) + 0.2 ∙ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒

Page 76: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 76

Decision Trees don’t make assumptions

But it only works well when trained with representative data

𝑦 = 𝑥2 + 0.2 ∙ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒 𝑦 = sin(1.5 ∙ 𝑥) + 0.2 ∙ 𝐺𝑎𝑢𝑠𝑠𝑖𝑎𝑛𝑁𝑜𝑖𝑠𝑒

Page 77: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 77

Ensembles

• Ensemble = group of Machine Learning models

• Each model in the group produces a different prediction

• Predictions are combined to give a final prediction

• How predictions are combined?

• voting

• bagging

• boosting

• stacking

Page 78: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 78

Ensembles - Voting

Logistic Regression

Support Vector Machine

Decision Tree

New sample

1

0

1

1

It works better than individual modelsAs long as models are independent, their errors compensate each other

Already trained models

Page 79: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 79

Ensembles - Bagging

• Voting of several instances of the same model

• majority voting from several trees

• However

• all tress would be so similar that their errors will not compensate

• Let’s make Decision Trees different so that we can combine them

Page 80: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 80

Ensembles - Bagging

Training Data

Random sampling

Random Sampling

Random Sampling

model

model

model

1

0

1

1

Training the models Using the models

Train decision models with different data / features

New sample

Page 81: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 81

Random Forest: Bagging Ensemble of Trees

Training Data

Random sampling

Random Sampling

Random Sampling

Decision Tree

Decision Tree

Decision Tree

Train decision models with different data / features

1

0

1

1

Training the models Using the modelsNew sample

Page 82: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 82

Random Forests

Random Forest are good for generalization

Random Forest provide a similar training error (same bias) as an individual treeRandom Forest provide lower testing error (lower variance) as an individual tree

Page 83: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 83

How results are combined for Random Forest?

Classification

• Soft-voting

• Combine the probabilities:

highly confident predictions

get higher weight

Regression

• Mean value

You can also implement your own combination of predictions

Page 84: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 84

How results are combined for Random Forest?

Custom combinations of the Decision Trees Ensembles

Page 85: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 85

Decision Trees or Random Forest?

Decision Tree

• You are interested in a

white-box model

• Understanding is more

important than predicting

Random Forest

• You don’t mind using a

black-box model

• Predicting (generalizing

well on new data) is

more important than

understanding

Tree + Random Forest

• Decision Tree for

understanding

• Random Forest for

predicting

• Use Tree as surrogate of

the Random Forest

Page 86: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 86

Surrogate Models

Black Box(e.g. Random Forest)

Results

FeaturesPredicted Results

Page 87: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 87

Surrogate Models

Black Box(e.g. Random Forest)

Results

FeaturesPredicted Results

White Box(e.g. Decision Tree)

Predicted Results (II)

Page 88: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 88

Random Forests

Random Forests gives you forecasting super-powers

But only if new data is similar to training data

It’s not as bad as I pictured it

Because, in practice, there are many more features

Page 89: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 89

Let’s recap

Today we have discussed about:

• What is machine learning

• Some applications in industry & space

• What is the ‘Learning’ in Machine Learning

• Types of machine learning

• Regression / Classification

• Machine Learning workflow

• Generalization

• Decision Trees

• Ensembles

• Random Forests

• Surrogates models for Explainable AI

Page 90: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 90

Thank you

LinkedIn: https://www.linkedin.com/in/josemartinezheras/

https://github.com/jmartinezheras/2018-MachineLearning-Lectures-ESA

Page 91: Machine Learning Introduction - Indico · ESA UNCLASSIFIED - For Official Use Jose Martinez Heras | ESOC | 16/04/2019 | Slide 10 Which tasks can Machine Learning perform? - Let’s

ESA UNCLASSIFIED - For Official Use

Thank you

LinkedIn: https://www.linkedin.com/in/josemartinezheras/

Jose Martinez Heras