Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and...

56
Session 124TS, A Practical Guide to Machine Learning for Actuaries Presenters: Dave M. Liner, FSA, MAAA, CERA SOA Antitrust Disclaimer SOA Presentation Disclaimer

Transcript of Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and...

Page 1: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Session 124TS, A Practical Guide to Machine Learning for Actuaries

Presenters: Dave M. Liner, FSA, MAAA, CERA

SOA Antitrust Disclaimer SOA Presentation Disclaimer

Page 2: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

27 JUNE 2018

Dave Liner

A practical guide to machine learning for actuaries

Page 3: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 4: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 5: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Rank 2009 2010 2011 2012 2013 2014 2015 2016 2017123456789

1011

CareerCast top job rankings by yearActuary

Page 6: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Rank 2009 2010 2011 2012 2013 2014 2015 2016 2017123456789

1011

CareerCast top job rankings by yearActuary

Data Scientist

Statistician

Page 7: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 8: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 9: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 10: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

9

Page 11: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 12: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 13: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

12

What I learned about machine learning

1. Machine learning drives disruption and innovation in many sectors globally

2. Many actuaries already do most of the machine learning process

3. Most popular machine learning methods are based on concepts that actuaries already understand

4. There is a staggering amount of free resources to develop machine learning skills

Page 14: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

13

Actuaries already do most of the machine learning process

1. Get data2. Prepare data3. Build model4. Use model to gain insight5. Tell others about model results

Page 15: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

14

We will review five machine learning methods today

k-Nearest neighborsk-Means clusteringDecision treesLinear regressionLogistic regressionNeural networks

Page 16: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Illustrative dataset

15

Page 17: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

16

X1 = Petal lengthX2 = Petal widthY = Species

Page 18: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

17

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

It is easier to illustrate methods using 2-dimensional data

Page 19: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

k-Nearest neighbors

18

Page 20: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

19

What is the species of a new sample based on Petal width and length using kNN?

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Virginica

Versicolor

Page 21: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

20

What is the species of a new sample based on petal width and length using kNN?

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Virginica

Versicolor

Page 22: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

21

Four lines of Python code gets same result as Excel kNN file

import sklearn.datasets as ds, sklearn.model_selection as ms, sklearn.preprocessing as pp, sklearn.neighbors, sklearn.metrics

X_train,X_test,y_train,y_test = ms.train_test_split(pp.scale(ds.load_iris().data),ds.load_iris().target,test_size=30,random_state=0)

y_pred_kNN = sklearn.neighbors.KNeighborsClassifier(n_neighbors=3).fit(X_train,y_train).predict(X_test)

print(sklearn.metrics.confusion_matrix(y_test, y_pred_kNN))

Page 23: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

k-Means clustering

22

Page 24: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

23

What is the species of a new sample based on Petal width and length using clustering?

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Unsupervised learning does not require labels (Y)

Page 25: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length24

Step 1: select random centroids (k=3 in this case)

Page 26: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

25

Step 2: move centroids based on data

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Page 27: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

26

Step 3: keep moving centroids until no points are reassigned

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Page 28: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

27

Step 4: assign each point to a centroid cluster

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Page 29: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

28

Step 4: assign each point to a centroid cluster

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Virginica

Versicolor

Page 30: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

29

Step 5: use clusters to assign new data points

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Virginica

Versicolor

Page 31: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

30

Step 5: use clusters to assign new data points

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Virginica

Versicolor

Page 32: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

31

Step 5: use clusters to assign new data points

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Virginica

Versicolor

Page 33: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Decision trees

32

Page 34: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

33

Page 35: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

34

Decision trees provide another method for classification

Setosa VirginicaVersicolor

Root Node

Decision Node

Leaf Nodes

Page 36: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

35

Decision trees provide another method for classification

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

Page 37: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

36

Decision trees provide another method for classification

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

Page 38: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

37

Decision trees provide another method for classification

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

Page 39: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

38

Decision trees provide another method for classification

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

Page 40: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

39

Decision trees provide another method for classification

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

Page 41: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

40

Decision trees provide another method for classification

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

Page 42: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Logistic regression

41

Page 43: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

42

Linear regression uses line of best fit to make numerical predictions

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Page 44: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

43

Logistic regression is a classification algorithm

0.0

0.5

1.0

0.0 0.5 1.0 1.5 2.0 2.5

Is it Virginica?

Petal Width

Setosa

Versicolor

Virginica

Yes

No

Page 45: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

44

Is it virginica?

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

0.0

0.5

1.0

0.0 0.5 1.0 1.5 2.0 2.5

Virginica?

Petal Width

Yes

No

Page 46: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

45

Is it virginica?

0.0

0.5

1.0

1.5

2.0

2.5

1.0 2.0 3.0 4.0 5.0 6.0 7.0

Petal Width

Petal Length

Setosa

Versicolor

Virginica

0.0

0.5

1.0

0.0 0.5 1.0 1.5 2.0 2.5

Virginica?

Petal Width

Yes

No

Page 47: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Neural networks

46

Page 48: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

47

Neural can model non-linear situations

Setosa

Versicolor

Virginica

Sepal Length

Petal Width

Sepal Width

Petal Length

Activation Functions

Input Hidden Output

Page 49: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

48

Neural NetworksInput Layer Hidden Layer Output Layer

Page 50: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

49

Neural NetworksInput Layer Hidden Layer Output Layer

Page 51: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

50

Neural NetworksInput Layer Hidden Layer Output Layer

Page 52: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

51

Neural NetworksInput Layer Hidden Layer Output Layer

Page 53: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

52

Summary of methods

Unsupervised Deep Regression

k-Nearest Neighbors

k-Means Clustering

Decision Trees

Linear Regression

Logistic Regression

Neural Networks

Page 54: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

Next steps

53

Page 55: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning
Page 56: Session 124 Teaching Session: A Practical Guide to Machine ... learning drives disruption and innovation in many sectors globally 2. Many actuaries already do most of the machine learning

55

Possible machine learning applications in healthcare include

Predicting non-adherent drug event before it happensPredict opioid drug abuse before it happensEstimate member persistency based on member and dependent characteristicsProject medical costs using personal and clinical dataDevelop clinical best-practices by linking clinical and financial data