0% found this document useful (0 votes)
9 views28 pages

3 4 MachineLearning

This document discusses machine learning and its applications. It covers several key topics: 1) Classical economic assumptions like perfect rationality no longer apply in today's markets with increased leverage and computer trading. 2) Machine learning uses techniques like supervised and unsupervised learning to build predictive models from large amounts of data. 3) Proper problem formulation and data preparation are essential for machine learning to be effective. Garbage in results in garbage out.

Uploaded by

石迪文
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views28 pages

3 4 MachineLearning

This document discusses machine learning and its applications. It covers several key topics: 1) Classical economic assumptions like perfect rationality no longer apply in today's markets with increased leverage and computer trading. 2) Machine learning uses techniques like supervised and unsupervised learning to build predictive models from large amounts of data. 3) Proper problem formulation and data preparation are essential for machine learning to be effective. Garbage in results in garbage out.

Uploaded by

石迪文
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Machine Learning 09/02/2024

Machine Learning

Edward Tsang

The Story So Far…

The competition is in seeking


Classical Economic assumptions
Computation & its limitations

Edward Tsang (all rights reserved) 1


Machine Learning 09/02/2024

Classical Economics
Built on critical assumptions

Everybody is perfectly rational Market has changed!


Everybody thinks the same Increased leverage
Everybody has full information Computer trading

How to beat your opponents?

Edward Tsang (all rights reserved) 2


Machine Learning 09/02/2024

The competition is in seeking

Machine
Learning

Combinatorial
Explosion

Machine Learning Overview


Unsupervised Learning
Supervised Learning • Supervised learning
Data Observed Target is function-fitting
Training

x1 x2 ... xn y • Does function f


1.6 7.1 ... 2.7 Buy exist?
1.4 6.8 ... 3.1 Sell
Testing

2.1 5.4 ... 2.8 Hold What y to learn?


... ...
How to prepare x?
Learning
Machine

How should f look like?


How to evaluate f ?
Unseen Function
Predictions How to find f ?
data y = f(x)
Where to pay attention to?
20

Edward Tsang (all rights reserved) 3


Machine Learning 09/02/2024

Where to spend your time in ML?


(Indicative, not in scale)
Problem analysis

Define Target
Investigator
Data preparation

Which ML method?
Off the shelf
whenever possible
Apply ML method

ML methods Interpret results


development
takes years Revise the above

21

Garbage In, Garbage Out

Machine
Learning
program

22

Edward Tsang (all rights reserved) 4


Machine Learning 09/02/2024

Take Home Messages


• Machine learning is powerful
–But no magic!
• Supervised learning is function fitting
–It can only learn functions that exist
• It relies on your domain knowledge
–To provide it with the right input data

23

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

24

Edward Tsang (all rights reserved) 5


Machine Learning 09/02/2024

28

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

29

Edward Tsang (all rights reserved) 6


Machine Learning 09/02/2024

Classification Performance

Edward Tsang

30

Reality Prediction
Confusion Matrix – –
+ +
+ –
Prediction – –
– –
- +
– –
Reality

- 5 2 7
+ +
+ 1 2 3
– +
6 4 10
– +
– –

32

Edward Tsang (all rights reserved) 7


Machine Learning 09/02/2024

Performance Measures

Ideal classification Program classification

- + - +

Reality
Reality

- 7 0 7 - 5 2 7
+ 0 3 3 + 1 2 3
7 3 10 6 4 10

RC = (5+2) ÷10 = 70%


Precision = 2 ÷ 4 = 50%
Recall = 2 ÷ 3 = 67%

33

Confusion Matrix Summary


Predictions
E.g. I predicted
(which I can control) earthquake, but it did
 + not happen

 True Negative False Positive Negative


(which I cannot

Type I Error Cases


control)
Reality

+ False Negative True Positive Positive


Type II Error Cases
E.g. I predicted an Negative Positive
investment is not Predictions Predictions
profitable, but it is

34

Edward Tsang (all rights reserved) 8


Machine Learning 09/02/2024

More on Performance Measures

Program classification False Positive Rate =


FP/(FP+TN) = 2/(2+5)
- + = 14%
Reality

- TN 5 FP 2 7
True Positive Rate =
+ FN 1 TP 2 3
recall = TP/(TP+FN) =
6 4 10
2/(2+1) = 67%
TN = True Negative
FN = False Negative = Miss = Type II Error
FP = False Positive = False Alarm = Type I Error
TP = True Positive

37

Receiver Operating Characteristic


(ROC)
1.0
• Each prediction measure Perfect
occupies one point classification
True Positive Rate

0.8
– Points on diagonal represent
random predictions
• A curve can be fitted on 0.6

multiple measures
Random
– Note: points may not cover 0.4
classifications
widely
• Area under the curve 0.2
measures the classifier’s
performance 0.0
0.0 0.2 0.4 0.6 0.8 1.0
False Positive Rate

38

Edward Tsang (all rights reserved) 9


Machine Learning 09/02/2024

Receiver Operating Characteristic


(ROC) Liberal
classifiers
1.0
• A classifier may occupy Perfect
classification
only one area in the ROC

True Positive Rate


0.8
space
• Other classifiers may 0.6
occupy multiple points Random
classifications
• Some classifiers may be 0.4

tuned to occupy different


parts of the curve 0.2
Cautious
classifiers
0.0
0.0 0.2 0.4 0.6 0.8 1.0
False Positive Rate

39

Receiver Operating Characteristic


(ROC)
• Which Classifier is better? 1.0

Predictions Classifier 1
True Positive Rate

0.8
− +
− 300 200 500
Reality

0.6
+ 100 400 500
400 600 1000 0.4 Classifier 2

− + 0.2

− 400 100 500


Reality

0.0
+ 200 300 500
0.0 0.2 0.4 0.6 0.8 1.0
600 400 1000 False Positive Rate

41

Edward Tsang (all rights reserved) 10


Machine Learning 09/02/2024

Learning Rare Events

43

Scarce opportunities 1
Ideal Predictions Easy Predictions

 +  +
 9,900 0 99%  9,900 0 99%
Reality

+ 0 100 1% + 100 0 1%
99% 1% 100% 0%

Ideal prediction Easy score on accuracy


Accuracy = Precision = Recall = 100% Accuracy = 99%, Precision = ?
Recall = 0%

• Easy to achieve high accuracy


• Worthless predications

44

Edward Tsang (all rights reserved) 11


Machine Learning 09/02/2024

Scarce opportunities 2
Easy Predictions Random Predictions
 +  +
 9,900 0 99%  9,801 99 99%
Reality

+ 100 0 1% + 99 1 1%
100% 0% 99% 1%

Easy score on accuracy Random move from  to +


Accuracy = 99%, Precision = ? Accuracy = 98.02%
Recall = 0% Precision = Recall = 1%

• Unintelligent improvement of recall


– Random +’ve predictions

45

Scarce opportunities 3
Random Predictions Predictions
 +  +
 9,801 99 99%  9,810 90 99%
Reality

+ 99 1 1% + 90 10 1%
99% 1% 99% 1%
Random move from  to + Better moves from  to +
Accuracy = 98.02% Accuracy = 98.2%
Precision = Recall = 1% Precision = Recall = 10%

• A more useful predication


• Sacrifice accuracy (from 99% in easy prediction)

46

Edward Tsang (all rights reserved) 12


Machine Learning 09/02/2024

Basic Machine Learning Methods

47

Artificial Neural Networks

Edward Tsang

61

Edward Tsang (all rights reserved) 13


Machine Learning 09/02/2024

Inspiration
• A average human brain has
– 86 billion (8.6 x 1010) neurons
– Used as storage as well as working memory
• A desktop PC may have:
– 8GB (8 x 109) RAM
– 1 Terabyte (1012) of storage
• Human brains are very efficient
• Connections between neurons matter!

62

Artificial Neural Network (ANN)


Update weights
Compare output with Target
in Supervised Learning
…..

Hidden
Input Units Output
Units Units

63

Edward Tsang (all rights reserved) 14


Machine Learning 09/02/2024

ANN – Deep Learning


Update weights

Compare output with Target


…..

Input …..
Hidden Units Output
Units Units

64

AlphaGo Master
AlphaGo 4-1 Lee Sedol, 2016

AlphaGo 3-0 Ke Jie, 2017

65

Edward Tsang (all rights reserved) 15


Machine Learning 09/02/2024

AlpahGo Zero’s Network


19x19 positions, each take a value from

A value for each position on the board


{empty, black, white}

…..

Input …..
Hidden Units Output
Units Units

67

Genetic Algorithms

Edward Tsang

68

Edward Tsang (all rights reserved) 16


Machine Learning 09/02/2024

Terminology in GA
String with
1 0 0 0 1 1 0 Chromosome
Building blocks
with Genes
with values
with alleles
evaluation

fitness

• Example of a candidate solution


• in binary representation (vs real coding)
• A population is maintained

69

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
– Fitness: f(x) = 295
 Note: representation issue can be tricky
 Choice of representation is crucial

70

Edward Tsang (all rights reserved) 17


Machine Learning 09/02/2024

Example Initial Population


To maximize f(x) = 100 + 28x – x2

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
Accum 1,018
averg 254.5

71

Selection of Parents

• Roulette Wheel 24%


Method 10101 28%
01010
– The fitter a string, the
more chance it has to
19%
be selected 29%
11000
01101

72

Edward Tsang (all rights reserved) 18


Machine Learning 09/02/2024

Crossover

Parents Offspring F(x)
1 0 1 0 1 1 0 0 1 0 18 280
0 1 0 1 0 0 1 1 0 1 13 295

0 1 1 0 1 0 1 1 1 0 14 296
0 1 0 1 0 0 1 0 0 1 9 271

 Sum of fitness: 1,142


Average fitness: 285.5

73

Mutations

0 1 1 0 1 0 1 1 1 1

Occasionally (e.g. 0.01%) change a value

74

Edward Tsang (all rights reserved) 19


Machine Learning 09/02/2024

Evolution in GA
0 1 0 1 0
Replace Population of strings 0
1
1
1
1
0
0
0
1
0
1 0 1 0 1

24%
28%
10101
01010
Selection 19% 29%
11000 01101

1 0 1 0 1
New
Parents 0 1 0 1 0
Population
Crossover 
[Mutation]
1 0 1 1 0
Offspring
0 1 0 0 1

75

Exploitation vs Exploration
• To succeed, GA must maintain a healthy
balance between exploitation and exploration
• Exploitation: encourage fitness
– In Selection, fit strings have a higher chance of
being picked as parents
• Exploration: allow randomness
– Selection also depends on randomness
– Crossover and Mutation are both completely
random operations

76

Edward Tsang (all rights reserved) 20


Machine Learning 09/02/2024

GA Expertise required

• Many variations of GAs


• Solution representation is sometimes tricky

77

Unsupervised Learning in Markets

Edward Tsang

79

Edward Tsang (all rights reserved) 21


Machine Learning 09/02/2024

Building Artificial Markets


Agent 1
1. modelling 1. modelling
Agent 2
Artificial
2. interaction Market
3. Observe
Agent n

5. modify Prices, wealth, etc

4. Compare and Observed market data


contrast (“stylized facts”)
I may not know a good solution, but can tell what is good / bad

80

Why build artificial markets?

Testing
Agent 1
1. modelling
new2
1. modelling

Agent
Market
Artificial
trading 2. interaction Market
Mechanism
strategies
Agent n Design
3. Observe

5. modify Prices, wealth, etc


Stress testing:
4. Compare and Observed market data
Probing hypothetical
contrast (“stylized facts”)
situations
I may not know a good solution, but can tell what is good / bad

81

Edward Tsang (all rights reserved) 22


Machine Learning 09/02/2024

Modelling is never perfect


“All models are wrong, but some are
useful”
(Box and Draper, 1987)
“More calculation is better than less,
Some calculation is better than none”
(Sun Zi, 6BC)
多算胜,少算不胜,而何况于无算乎? 【孙子】

83

Modelling Take Home Messages

 Models help us to make informed


guesses…
… which are always better than
speculations!
 Unsupervised learning helps to
build better models more
efficiently

84

Edward Tsang (all rights reserved) 23


Machine Learning 09/02/2024

Machine Learning Summary


• Supervised 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 (NN, EA)
• Caution: avoid too much faith
• Unsupervised learning is generate and test
– One knows what is good/bad when one sees it

85

Supplementary Information

90

Edward Tsang (all rights reserved) 24


Machine Learning 09/02/2024

Deduction, Induction, Abduction,


Speculation

91

Modes of Knowledge Acquisition


• Deduction
– I know P  Q; I know P is true
– So I deduce Q is true
• Induction
– Sparrows can fly; owls can fly; pigeons can fly
– So I generalize that all birds can fly
• Abduction Profit Up  Price Up
– I know P  Q; I know Q is true Price Up
– So I hypothesize that P is true Profit Up
• Speculation – none of the above

92

Edward Tsang (all rights reserved) 25


Machine Learning 09/02/2024

Do you learn anything new in


deduction?

93

Does deduction tell you anything new?


• No, if you have maintained consequential
closure
• Nobody maintains consequential closure
• Deduction can tell you useful new facts, e.g.:
– Disproving something by refutation
– Prove by elimination

94

Edward Tsang (all rights reserved) 26


Machine Learning 09/02/2024

What is Machine Learning?

Deduction? Induction? Abduction?


Speculation?
None of the above?

95

Generate and Test


• Supervised learning attempts to relate input
variables to output variables
– Model relationships by strings, trees, networks, …
– Adjust parameters in the model through training
– Use data to tell how good a model is
• Unsupervised learning models solutions
– Use feedback to modify the model
– Test the fitness of the new model

96

Edward Tsang (all rights reserved) 27


Machine Learning 09/02/2024

Types of Data
Boolean
Nominal
Ordinal
Interval
Ratio

97

Data Types
• Boolean: True or False
• Nominal: {Dog, Cat, Horse, Monkey}
• Ordinal: 1st, 2nd, 3rd, 4th
• Interval: 1-10, 11-20, 21-30, 31-40
• Ratio: 2.4, 7.8

98

Edward Tsang (all rights reserved) 28

You might also like