machine learning overview machine learning is function fitting does function f exist? target y buy...
TRANSCRIPT
![Page 1: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/1.jpg)
Machine Learning Overview
• Machine learning is function fitting
• Does function f exist?
Targety
BuySellHold
...
Mac
hine
Le
arni
ng
Supervised LearningTr
aini
ngTe
stin
g
Unseen data
Predictions How to find f ?
How to evaluate f ?
What y to learn?
How to prepare x?
How should f look like?
Patternsy = f(x)
Data Observed x1 x2 ... xn
1.6 7.1 ... 2.71.4 6.8 ... 3.12.1 5.4 ... 2.8...
![Page 2: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/2.jpg)
What to learn?
• We could try to predict the price tomorrow• We cold try to predict whether prices will
go up (or down) by a margin– E.g. will the price go up by r% within n days?
• Notes:– Always ask: can the market be predicted?– There is no magic in machine learning– Harder task less chance to succeed
Edward Tsang (All rights reserved)
![Page 3: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/3.jpg)
FTSE 2009.08.18-2010.10.22
20 April 2023 All Rights Reserved, Edward Tsang
![Page 4: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/4.jpg)
FTSE 2009.08.18-2010.10.22
20 April 2023 All Rights Reserved, Edward Tsang
![Page 5: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/5.jpg)
Moving Average Rules to Find• Let
– m-MA be the m-days moving average– n-MA be the n-days moving average– m < n
• Possible rules to find: If the m-MA ≤ n-MA, on day d, but m-MA > n-MA on
day d+1, then buy If the m-MA ≥ n-MA, on day d, but m-MA < n-MA on
day d+1, then sell
20/04/23 All Rights Reserved, Edward Tsang
![Page 6: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/6.jpg)
Confusion MatrixReality Prediction
– –
+ +
+ –
– –
– –
– –
+ +
– +
– +
– –
– +
– 5 2 7
+ 1 2 3
6 4 10
Edward Tsang (All rights reserved)
Prediction
Real
ity
![Page 7: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/7.jpg)
Performance Measures
+
7 0 7
+ 0 3 3
7 3 10
Edward Tsang (All rights reserved)
Ideal Predictions
Real
ity
+
5 2 7
+ 1 2 3
6 4 10
RC = (5+2) ÷10 = 70%Precision = 2 ÷ 4 = 50%
Recall = 2 ÷ 3 = 67%
Actual Predictions, Example
![Page 8: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/8.jpg)
Matthews correlation coefficient (MCC)
• MCC measures the quality of binary classifications– Range from -1 to 1– (Related to Chi-square 2)
Edward Tsang (All rights reserved)
Real
ity
+
TN FP O
+ FN TP O+
P P+ n
Predictions
nMCC
2
PPOO
FNFPTNTPMCC
![Page 9: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/9.jpg)
More on Performance Measures
False Positive Rate = FP/(FP+TN) = 2/(2+5) = 14%
True Positive Rate = recall = TP/(TP+FN) = 2/(2+1) = 67%
Edward Tsang (All rights reserved)
Real
ity
+
TN 5 FP 2 7
+ FN 1 TP 2 3
6 4 10
Predictions
TN = True NegativeFN = False Negative = Miss = Type II ErrorFP = False Positive = False Alarm = Type I ErrorTP = True Positive
![Page 10: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/10.jpg)
Receiver Operating Characteristic (ROC)
• Each predication measure occupies one point– Points on diagonal represent
random predictions• A curve can be fitted on
multiple measures– Note: points may not cover
widely• Area under the curve
measures the classifier’s performance
Edward Tsang (All rights reserved)
False Positive Rate
Tru
e P
osit
ive
Rat
e
Perfect classification
Random classifications
1.0
0.0
0.8
0.4
0.2
0.6
1.00.0 0.80.40.2 0.6
(0.14, 0.
67) Better
![Page 11: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/11.jpg)
Receiver Operating Characteristic (ROC)
• A classifier may occupy only one area in the ROC space
• Other classifiers may occupy multiple points
• Some classifiers may be tuned to occupy different parts of the curve
Edward Tsang (All rights reserved)
False Positive Rate
Tru
e P
osit
ive
Rat
e
Perfect classification
Random classifications
1.0
0.0
0.8
0.4
0.2
0.6
1.00.0 0.80.40.2 0.6
Cautious classifiers
Liberal classifiers
![Page 12: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/12.jpg)
Scarce opportunities 1
• Easy to achieve high accuracy• Worthless predications
20 April 2023 All Rights Reserved, Edward Tsang
+ 9,900 0 99%
+ 0 100 1%
99% 1%
Ideal Predictions
Realit
y
Ideal prediction Accuracy = Precision = Recall = 100%
+
9,900 0 99%
+ 100 0 1%
100% 0%
Easy score on accuracyAccuracy = 99%, Precision = ?
Recall = 0%
Easy Predictions
![Page 13: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/13.jpg)
Scarce opportunities 2
• Unintelligent improvement of recall– Random +’ve predictions
20 April 2023 All Rights Reserved, Edward Tsang
+ 9,801 99 99%
+ 99 1 1%
99% 1%
Realit
y
Random Predictions
Random move from to +Accuracy = 98.02%
Precision = Recall = 1%
+
9,900 0 99%
+ 100 0 1%
100% 0%
Easy score on accuracyAccuracy = 99%, Precision = ?
Recall = 0%
Easy Predictions
![Page 14: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/14.jpg)
Scarce opportunities 3
• A more useful predication• Sacrifice accuracy (from 99% in easy prediction)
20 April 2023 All Rights Reserved, Edward Tsang
Realit
y
Predictions
+ 9,810 90 99%
+ 90 10 1%
99% 1%
Better moves from to +Accuracy = 98.2%
Precision = Recall = 10%
+ 9,801 99 99%
+ 99 1 1%
99% 1%
Random Predictions
Random move from to +Accuracy = 98.02%
Precision = Recall = 1%
![Page 15: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/15.jpg)
Machine Learning Techniques
• Early work: Quinlan’s ID3 / C4.5/ C5– Building decision trees
• Neural networks– A solution is represented by a network– Learning through feedbacks
• Evolutionary computation– Keep a population of solutions– Learning through survival of the fittest
Edward Tsang (All rights reserved)
![Page 16: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/16.jpg)
ID3 for machine learning
• ID3 is an algorithm invented by Quinlan• ID3 performs supervised learning• It builds decision trees• Perfect fitting with training data• Like other machine learning techniques:
– No guarantee that it fits testing data– Danger of “over-fitting”
Edward Tsang (All rights reserved)
![Page 17: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/17.jpg)
Example Classification Problem: Play Tennis?Day Outlook Temper. Humid. Wind Play?
1 Sunny Hot High Weak No 2 Sunny Hot High Strong No 3 Overcast Hot High Weak Yes 4 Rain Mild High Weak Yes 5 Rain Cool Normal Weak Yes 6 Rain Cool Normal Strong No 7 Overcast Cool Normal Strong Yes 8 Sunny Mild High Weak No 9 Sunny Cool Normal Weak Yes 10 Rain Mild Normal Weak Yes 11 Sunny Mild Normal Strong Yes 12 Overcast Mild High Strong Yes 13 Overcast Hot Normal Weak Yes 14 Rain Mild High Strong No
12
Edward Tsang (All rights reserved)
![Page 18: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/18.jpg)
Example Decision Tree
• Decision to make: play tennis?
Edward Tsang (All rights reserved)
Humidity Wind
Outlook
Yes
Yes YesNoNo
Sunny Overcast Rain
Strong WeakHigh Normal
![Page 19: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/19.jpg)
Example: ID3 Picks an attribute
• Pick an attribute A• Compute Gain(S, A):
– Outlook: 0.246– Humidity: 0.151– Wind: 0.048– Temperature: 0.029
• Outlook is picked
Edward Tsang (All rights reserved)
D1-, D2-, D8-, D9+, D11+
D4+, D5+, D6-,
D10+, D14-
Outlook
Yes
Sunny Overcast Rain
[2+, 3-] [3+, 2-]
D3+, D7+,
D12+, D13+
[4+, 0-]
![Page 20: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/20.jpg)
Simplified ID3 in Action (1)
1) Not all examples agree on conclusion
2) Pick one attribute “Outlook” is picked
3) Divide examples according to values in Outlook
4) Build each branch recursively
“Yes” for “Overcast”
Edward Tsang (All rights reserved)
D1-, D2-, D8-, D9+, D11+
D4+, D5+, D6-,
D10+, D14-
Outlook
Yes
Sunny Overcast Rain
[2+, 3-] [3+, 2-]
D3+, D7+,
D12+, D13+
[4+, 0-]
![Page 21: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/21.jpg)
Simplified ID3 in Action (2)
1) Expand Outlook=Sunny2) Not all examples agree3) Pick one attribute
“Humidity” is picked
4) Divide examples5) Build two branches
“No” for “High” “Yes” for “Normal”
Edward Tsang (All rights reserved)
D9+, D11+
Outlook = SunnyD1-, D2-, D8-, D9+, D11+
Humidity
Yes
High Normal
D1-, D2-, D8-
No
![Page 22: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/22.jpg)
Simplified ID3 in Action (3)
1) Expand Outlook=Rain2) Not all examples agree3) Pick one attribute
“Wind” is picked
4) Divide examples5) Build two branches
“No” for “Strong” “Yes” for “Weak”
Edward Tsang (All rights reserved)
D4+, D5+, D10+
Outlook = RainD4+, D5+, D6-, D10+, D14-
Wind
Yes
Strong Weak
D6-, D14-
No
![Page 23: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/23.jpg)
ID3 in Action – Tree Built
Edward Tsang (All rights reserved)
Humidity Wind
Outlook
Yes
Yes YesNoNo
Sunny Overcast Rain
Strong WeakHigh Normal
D4+, D5+, D10+
D6-, D14-
D9+, D11+
D1-, D2-, D8-
D3+, D7+, D12+, D13+
![Page 24: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/24.jpg)
Remarks on ID3• Decision trees are easy to understand• Decision trees are easy to use• But what if data has noise?
– I.e. under the same situation, contradictory results were observed
• Besides, what if some values are missing from the decision tree?– E.g. “Humidity = Low”
• These are handled by C4.5 and See5 (beyond our syllabus)
Edward Tsang (All rights reserved)
![Page 25: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/25.jpg)
Exercise Classification Problem - Admit?
Student Maths English Physics IT Exam
1 A A C B Admit
2 A A A C Admit
3 A B C A Admit
4 A A B A Admit
5 B A A C Admit
6 B B C A Admit
7 A B B B Admit
8 B A B C Admit
9 B B A B Admit
10 C A B A Admit
11 C A C A Reject
12 A C C B Reject
13 C A B C Reject
14 B C A C Reject
Edward Tsang (All rights reserved)
Supp
ose
the
rule
is: “
Onl
y ac
cept
stu
dent
s wi
th a
t le
ast t
hree
(A o
r B)s
, inc
ludi
ng a
t lea
st o
ne A
”. Co
uld
ID3
find
it?
![Page 26: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/26.jpg)
ID3 Exercise: “admit or reject”
Edward Tsang (All rights reserved)
Maths
English
Admit
Reject
…
A B C
B C
12-, 14-
1+, 2+, 4+
10+, 11-, 13-
3+, 6+,
7+, 9+A
Admit
5+, 8+ Admit
Will the rule found admit students with (B, B, B, B), or (C, A, A, B)?
![Page 27: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/27.jpg)
Lessons from the exercise
• Without the right columns in the database, one cannot learn the underlying rule– It would help if there were a value “A or B”
• Rules generalise– they may not be correct
• Some branches may not be covered– Not shown in the above slide
Edward Tsang (All rights reserved)
![Page 28: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/28.jpg)
Machine Learning Summary• Machine learning is function fitting• First question: what function to find?• Do such functions exist?
– If not, all efforts are futile• How to measure success?• Finally, find such functions (ID3, NN, EA)
(No more important than the above questions)• Caution: avoid too much faith
(There is too much hype!)
Edward Tsang (All rights reserved)
![Page 29: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/29.jpg)
Artificial Neural Network
Thursday 20 April 2023 Edward Tsang (Copyright) 32
…..
HiddenUnits Output
UnitsInputUnits
Com
pare
out
put
wit
h T
arge
tUpdate weights
![Page 30: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/30.jpg)
Terminology in GA
• Example of a candidate solution• in binary representation (vs real coding)• A population is maintained
20 April 2023 Copyright Edward Tsang 33
1 0 0 0 1 1 0 Chromosome with Geneswith alleles
String withBuilding blocks
with values
fitness
evaluation
![Page 31: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/31.jpg)
Example Problem For GA
• maximize f(x) = 100 + 28x – x2
– optimal solution: x = 14 (f(x) = 296)
• Use 5 bits representation– e.g. binary 01101 = decimal 13– f(x) = 295
Note: representation issue can be tricky Choice of representation is crucial
20 April 2023 Copyright Edward Tsang 34
![Page 32: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/32.jpg)
Example Initial Population
20 April 2023 Copyright Edward Tsang 35
No. String Decim. f(x) weight Accum
1 01010 10 280 28 28
2 01101 13 295 29 57
3 11000 24 196 19 76
4 10101 21 247 24 100
Accumaverg
1,018254.5
To maximize f(x) = 100 + 28x – x2
![Page 33: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/33.jpg)
Selection in Evolutionary Computation
• Roulette wheel method– The fitter a string,
the more chance it has to be selected
20 April 2023 Copyright Edward Tsang 36
24%10101 28%
01010
29%01101
19%11000
![Page 34: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/34.jpg)
Crossover
20 April 2023 Copyright Edward Tsang 37
1 0 1 0 1 1 0 0 1 0
0 1 1 0 1
18
13
280
295
F(x)
0 1 1 0 1 0 1 1 1 0
0 1 0 0 1
14
9
296
271
1,142
285.5
Sum of fitness:
Average fitness:
![Page 35: Machine Learning Overview Machine learning is function fitting Does function f exist? Target y Buy Sell Hold... Machine Learning Supervised Learning Training](https://reader036.vdocument.in/reader036/viewer/2022081513/56649ed05503460f94bddc3a/html5/thumbnails/35.jpg)
Evolutionary Computation:Model-based Generate & Test
20 April 2023 Copyright Edward Tsang 38
Model (To Evolve)
Candidate Solution
Observed Performance
Test
Feedback
(To update m
odel)
A Candidate Solution could be a vector of variables, or a tree
A Model could be a population of solutions, or a probability model
The Fitness of a solution is application-dependent,
e.g. drug testing
Generate: select, create/mutate vectors / trees