A practical guide to machine learning for actuaries · What I learned about machine learning 1....

55
17 OCTOBER 2018 Dave Liner A practical guide to machine learning for actuaries

Transcript of A practical guide to machine learning for actuaries · What I learned about machine learning 1....

Page 1: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

17 OCTOBER 2018

Dave Liner

A practical guide to machine learning for actuaries

Page 2: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many
Page 3: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many
Page 4: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

Rank 2009 2010 2011 2012 2013 2014 2015 2016 2017

1

2

3

4

5

6

7

8

9

10

11

CareerCast top job rankings by year

Actuary

Page 5: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

Rank 2009 2010 2011 2012 2013 2014 2015 2016 2017

1

2

3

4

5

6

7

8

9

10

11

CareerCast top job rankings by year

Actuary

Data Scientist

Statistician

Page 6: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many
Page 7: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many
Page 8: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many
Page 9: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

9

Page 10: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many
Page 11: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many
Page 12: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 13: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

13

Actuaries already do most of the machine learning process

1. Get data

2. Prepare data

3. Build model

4. Use model to gain insight

5. Tell others about model results

Page 14: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

14

We will review five machine learning methods today

k-Nearest neighbors

k-Means clustering

Decision trees

Logistic regression

Neural networks

Page 15: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

Illustrative dataset

15

Page 16: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

16

X1 = Petal length

X2 = Petal width

Y = Species

Page 17: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 18: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

k-Nearest neighbors

18

Page 19: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 20: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 21: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 22: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

k-Means clustering

Page 23: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 24: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 25: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 26: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 27: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 28: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 29: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 30: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 31: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 32: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

Decision trees

Page 33: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

33

Page 34: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

34

Decision trees provide another method for classification

Setosa VirginicaVersicolor

Root Node

Decision Node

Leaf Nodes

Page 35: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 36: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 37: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 38: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 39: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 40: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 41: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

Logistic regression

Page 42: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 43: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 44: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 45: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

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 46: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

Neural networks

Page 47: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

47

Neural can model non-linear situations

Setosa

Versicolor

Virginica

Sepal Length

Petal Width

Sepal Width

Petal Length

Activation Functions

Input Hidden Output

Page 48: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

48

Neural Networks

Input Layer Hidden Layer Output Layer

Page 49: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

49

Neural Networks

Input Layer Hidden Layer Output Layer

Page 50: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

50

Neural Networks

Input Layer Hidden Layer Output Layer

Page 51: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

51

Neural Networks

Input Layer Hidden Layer Output Layer

Page 52: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

52

Summary of methods

Unsupervised Deep Regression

k-Nearest Neighbors

k-Means Clustering

Decision Trees

Linear Regression

Logistic Regression

Neural Networks

Page 53: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

Next steps

Page 54: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many

54

Possible machine learning applications in healthcare include

Predicting non-adherent drug event before it happens

Predict opioid drug abuse before it happens

Estimate member persistency based on member and dependent characteristics

Project medical costs using personal and clinical data

Develop clinical best-practices by linking clinical and financial data

Page 55: A practical guide to machine learning for actuaries · What I learned about machine learning 1. Machine learning drives disruption and innovation in many sectors globally 2. Many