1
Applied Data Analysis (CS401)
Robert West
Lecture 9
Applied
machine learning
2018/11/15
Announcements
2
3
Give us feedback on this lecture here: https://go.epfl.ch/ada2018-lec9-feedback
Why an extra class on applied ML?
4
Classic ML
class
ADA
Classification pipeline
5
Data collection
Model assessment
Model selection
Data collection
The first step is collecting data related to the classification task.
Domain knowledge is needed.
What if assigning the class label would be too time-consuming or even impossible?
→ Unsupervised methods (e.g., clustering); cf. next lecture!
6
Data collection
7
Identification of features
Removing irrelevant features
Unsupervised/supervised discretisation
Discretisation?
Normalisation?
Standardisation/scaling
Y
N
Y
N
Class label available?
Y
N
Data labeling
Features
Different types of features [more]
New features can be generated from simple stats
Some classifiers require categorical features => Discretization
8
ML before 2012*
9
Cleverly designed�features
Input data
ML model
Most of the “heavy lifting” in here.
Final performance only as good as the�feature set.
A typical ML approach after 2012
10
Features
Input data
Model
Deep learning
Features and model learned together,�mutually reinforcing
Data collection
11
Identification of features
Removing irrelevant features
Unsupervised/supervised discretization
Discretisation?
Normalisation?
Standardisation/scaling
Y
N
Y
N
Class label available?
Y
Data labeling
N
Potential labelers
12
Labels
Collecting a lot of data (features) is easy
Labeling data is time consuming, difficult and sometimes even impossible
13
Label: “Is page credible?”
Dietary expert is needed
14
Requester
Crowdsourcing
platform
1. Submit task
2. Accept task
Crowd (workers)
3. Return answers
4. Collect answers
Is this webpage
credible?
C C ¬C C ¬C
Crowdsourcing
Different types of workers
15
Random Spammer
Uniform
Spammer
Malicious
Spammer
Expert
Normal
Worker
True negative rate
True positive rate
Uniform
Spammer
Catching malicious spammers
16
Crowdsourcing
Answer aggregation problem
17
Crowd (workers)
Worker | Webpage | Credible |
W1 | www.diet.com | C |
W2 | www.diet.com | ¬C |
W3 | www.diet.com | C |
... | ... | ... |
Aggregation
www.diet.com | C |
Data collection
18
Identification of features
Removing irrelevant features
Unsupervised/supervised discretization
Discretisation?
Normalisation?
Standardisation/scaling
Y
N
Y
N
Class label available?
Y
N
Data labeling
Discretization
Why?
19
Discretization
Unsupervised
20
Discretization
Supervised
21
Data collection
22
Identification of features
Removing irrelevant features
Unsupervised/supervised discretization
Discretisation?
Normalisation?
Standardisation/scaling
Y
N
Y
N
Class label available?
Y
N
Data labeling
Feature selection
Reducing the number of N features to a subset of the best size M < N
There are 2N possible subsets
Solutions
23
Offline feature selection
Rank features according to their individual predictive power; select the best ones
24
Ranking of features
Continuous features (and ideally labels)
Categorical features and labels
25
Ranking of features
Categorical features and labels (cont’d)
26
Ranking of features
Beware: collectively relevant features may look individually irrelevant!
27
Online feature selection
Forward feature selection: iteratively add features, using cross-validation to guide feature inclusion; stop when no improvement
28
Online feature selection
Backward selection (a.k.a. ablation): iteratively remove features, using cross-validation to guide feature removal; stop when no improvement
29
Cross-validation
30
Feature count vs. performance
31
Data collection
32
Identification of features
Removing irrelevant features
Unsupervised/supervised discretisation
Discretisation?
Normalisation?
Standardisation/scaling
Y
N
Y
N
Class label available?
Y
N
Data labeling
Feature normalization
Some classifiers do not manage well features with very different scales
Features with large values dominate the others, and the classifier tends to over-optimize them
33
Logarithmic scaling
xi’ = log(xi)
34
Min-max scaling
xi’ = (xi – mi)/(Mi – mi)
where Mi and mi are the max and min values of feature xi respectively
The new feature xi’ lies in the interval [0,1]
35
Standardization
xi’ = (xi – μi)/σi
where μi is the mean value of feature xi, and σi is the standard deviation
The new feature xi’ has mean 0 and �standard deviation 1
36
Dangers of standardization and scaling
Standardization:
Min-max scaling:
37
Classification pipeline
38
Data collection
Model assessment
Model selection
Model selection: high level
Need to choose type of model
39
Model selection: low level
Usually a classifier has some “hyperparameters” to be tuned
40
Model selection
Need evaluation metric!
41
Split dataset into “training” and “validation”
Evaluate classifier with validation set
Train classifier with training set
Performance acceptable?
Y
N
Set classifier parameters
Loss function (more of them later!)
Categorical output
Real-valued output
42
Model selection
43
Hyperparameter value
Loss function
Performance metrics for binary classification
For categorical binary classification, the usual metrics are based on the confusion matrix, which has 4 values:
44
| | Class | |
| | A | B |
Classified | A | TP | FP |
B | FN | TN | |
Accuracy
Appropriate metric when
45
Accuracy (skewed example)
A = 85/100 = 0.85
A = 90/100 = 0.90
46
Classifier 1 | Class | ||
Fraud | ¬Fraud | ||
Classified | Fraud | 5 | 10 |
¬Fraud | 5 | 80 | |
Always ¬Fraud | Class | ||
Fraud | ¬Fraud | ||
Classified | Fraud | 0 | 0 |
¬Fraud | 10 | 90 | |
Question time
Which is the “best” classifier?
47
Classifier 1 | Class | ||
A | B | ||
Classified | A | 45 | 20 |
B | 5 | 30 | |
Classifier 2 | Class | ||
A | B | ||
Classified | A | 40 | 10 |
B | 10 | 40 | |
Question time
Which is the “best” classifier?
48
Classifier 1 | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 45 | 20 |
¬Cancer | 5 | 30 | |
Classifier 2 | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 40 | 10 |
¬Cancer | 10 | 40 | |
Precision and recall
Precision: what fraction of positive predictions are actually positive?
Recall: what fraction of positive examples did I recognize as such?
49
Precision and recall
P1=45/65=0.69 P2=40/50=0.8
R1=45/50=0.9 R2=40/50=0.8
50
Classifier 1 | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 45 | 20 |
¬Cancer | 5 | 30 | |
Classifier 2 | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 40 | 10 |
¬Cancer | 10 | 40 | |
Everybody has cancer | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 50 | 50 |
¬Cancer | 0 | 0 | |
P = 50/100 = 0.5
R = 50/50 = 1
F-score
Sometimes it’s necessary to have a unique metric to compare classifiers
F-score (or F1-score): harmonic mean of precision and recall
Precision and recall can be differently weighted, if one is more important than the other
51
F1 = 1 / (0.5 * (1/P + 1/R)) =
Precision and recall
F1=2*(0.69*0.9)/(0.69+0.9) F2=2*(0.8*0.8)/(0.8+0.8)
= 0.78 =0.8
52
Classifier 1 | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 45 | 20 |
¬Cancer | 5 | 30 | |
Classifier 2 | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 40 | 10 |
¬Cancer | 10 | 40 | |
Everybody has cancer | Class | ||
Cancer | ¬Cancer | ||
Classified | Cancer | 50 | 50 |
¬Cancer | 0 | 0 | |
F=2*(0.5*1)/(0.5+1)=0.66
Precision/recall curve
53
Recap
54
Data collection
Model assessment
Model selection
| | Class | |
| | A | B |
Classified | A | TP | FP |
B | FN | TN | |
ROC plots
ROC = Receiver-Operating Characteristic (WTF?!)
Y-axis: true-positive rate = TP/(TP + FN), a.k.a. recall
X-axis: false-positive rate = FP/(FP + TN)
55
Decreasing classification threshold
False-positive rate
True-positive rate
ROC AUC
ROC AUC is the “Area under the curve” – a single number that captures the overall quality of the classifier. It should be between 0.5 (random classifier) and 1.0 (perfect).
56
Random ordering
area = 0.5
False-positive rate
True-positive rate
Bias and variance
57
Bias and variance
Bias and variance can be assessed by comparing the error metric on the training set and the test set => always plot learning curves (training set size vs. error)
In the ideal case, we want low bias (small training error) and low variance (small test error)
58
When more data helps
59
High bias
High variance
More data often beats better algorithms
60
Classification pipeline
61
Data collection
Model assessment
Model selection
Model assessment
Model assessment is the goal of estimating the performance of a fixed model (i.e., the best model found during model selection)
Use held-out test set that you’ve never seen during training
62
Important reads
63
64
Feedback
65
Give us feedback on this lecture here: https://go.epfl.ch/ada2018-lec9-feedback
Training and testing with heaps of data
66
database D
training set
test set
60% of D
40% of D
learn model
evaluate model
performance metric
Data-efficient training and testing:
Leave-one-out cross-validation
67
database D
training set
test set
(N-1)/N of D
1/N of D
learn model
evaluate model
Repeat N times
average of N runs
Data-efficient training and testing:
k-fold cross validation
68
database D
training set
test set
(k-1)/k of D
1/k of D
learn model
evaluate model
average of k runs
Repeat k times