Top Banner
Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research
33

Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Feb 15, 2019

Download

Documents

vobao
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Deep Learning with RFrancesca Lazzeri - @frlazzeriData Scientist II - Microsoft, AI Research

Page 2: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Agenda

Better understanding of R DL tools

Demo

Deep Learning

with R

What is Deep

Learning

Page 3: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningFundamental concepts in Deep Learning

Forward Propagation Algorithm

Activation Functions

Gradient Descent Backpropagation

Page 4: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningFundamental concepts in Deep Learning

Forward Propagation Algorithm

Gradient Descent Backpropagation

Activation Functions

Page 5: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

Learning

Age

Bank Balance

Retirement Status

Example as seen by linear regression

Number of Transactions

Page 6: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningInteractions

o Neural networks account for interactions really well

o Deep learning uses especially powerful neural networks for:* Text* Images* Videos* Audio* Source code

Page 7: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

Learning

Age

Bank Balance

Retirement Status

Deep learning models capture interactions

Number of Transactions

Page 8: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

Learning

Age

Bank Balance

Retirement Status

# Accounts

Interactions in neural networks

Number of Transactions

Input Layer

Hidden Layer

Output Layer

Page 9: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

Learning

2

3

Forward Propagation Algorithm

9

5

1

InputHidden

Output

# Children

# Accounts

# Transactions-1

1

1

1

-1

2

Page 10: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningFundamental concepts in Deep Learning

Activation Functions

Gradient Descent Backpropagation

Forward Propagation Algorithm

Page 11: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningActivation Functions

2

3

9

tanh (2+3)

tanh (-2+3)

InputHidden

Output

# Accounts

# Transactions-1

1

1

1

-1

2

# Children

Page 12: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningReLU Activation Function

3

5

Input

4

2

4

-5

364

0

52

Hidden

Output

7

-3

26

0

Hidden

1

-1

2

2

Page 13: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningRepresentation Learning

o Deep networks internally build representations of patterns in the data

o Partially replace the need for feature engineering

o Subsequent layers build increasingly sophisticated representations of raw data

o Modeler doesn’t need to specify the interactions

o When you train the model, the neural network gets weights that find the relevant patterns to make better predictions

Page 14: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningFundamental concepts in Deep Learning

Gradient Descent

Forward Propagation Algorithm

Backpropagation

Activation Functions

Page 15: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningThe Need for Optimization

o Predictions with multiple points* Making accurate predictions gets harder with more points* At any set of weights, there are many values of the error* Correspond to the many points we make predictions for

o Loss function* Aggregate errors in predictions from many data points into single number* Measure of model’s predictive performance

Page 16: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningThe Need for Optimization

o Squared error loss function

o Total Squared Error: 150o Mean Squared Error: 50o Lower loss function value means a better modelo Goal: find the weights that give the lowest value for the loss functiono Gradient descent!

Prediction Actual Error Squared Error

10 20 -10 100

8 3 5 25

6 1 5 25

Page 17: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningGradient Descent

Loss(w)

w

Page 18: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningGradient Descent

o Slope calculation example

Actual Target Value = 10

o To calculate the slope for a weight, need to multiply:* Slope of the loss function w.r.t value at the node we feed into* The value of the node that feeds into our weight* Slope of activation function w.r.t value we feed into

32

6

Page 19: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningFundamental concepts in Deep Learning

Backpropagation

Forward Propagation Algorithm

Gradient Descent

Activation Functions

Page 20: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningBackpropagation

3

5

Input

364

0

52

Hidden

Output26

0

Hidden

Page 21: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

What is Deep

LearningBackpropagation

o Allows gradient descent to update all weights in neural network (by getting gradientsfor all weights)

o Go back one layer at a time

o Important to understand the process, but you will generally use a library thatimplements this

Page 22: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Deep Learning

with R

• Feed-forward neural network

• Convolutional neural network (CNN)

MXNetR

• Restricted Boltzmann machine

• Deep belief network

darch

• Feed-forward neural network

• Restricted Boltzmann machine

• Deep belief network

• Stacked autoencoders

deepnet

• Feed-forward neural network

• Deep autoencoders

H2O

• Simplify some functions from H2O

• Deepnet packages

deepr

Page 23: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Deep Learning

with R

Model/Dataset

MNIST Iris Forest Cover Type

Accuracy (%) Runtime (sec) Accuracy (%) Runtime (sec) Accuracy (%) Runtime (sec)

MXNetR (CPU) 98.33 147.78 83.04 1.46 66.8 30.24

MXNetR (GPU) 98.27 336.94 84.77 3.09 67.75 80.89

darch 100 92.09 1368.31 69.12 1.71 – –

darch 500/300 95.88 4706.23 54.78 2.1 – –

deepnet DBN 97.85 6775.4 30.43 0.89 14.06 67.97

deepnet DNN 97.05 2183.92 78.26 0.42 26.01 25.67

H2O 98.08 543.14 89.56 0.53 67.36 5.78

Random Forest 96.77 125.28 91.3 2.89 86.25 9.41

Page 24: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Deep Learning

with RR interface to Keras

Page 25: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Demo Deep Learning with R on Azure with Keras and CNTK

DSVM CNTK R & Keras

Page 26: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Demo Keras Workflow Steps to Build your Model

o Specify architecture

o Compile the model

o Fit the model

o Predict

Page 27: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Demo Preparing the Data

Page 28: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Demo Defining the Model

Page 29: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Demo Defining the Model

Page 30: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Demo Defining the Model

Page 31: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Demo Training and Evaluation

Page 32: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

References

http://blog.revolutionanalytics.com/2017/08/keras-and-cntk.html

http://www.rblog.uni-freiburg.de

https://keras.rstudio.com/

https://campus.datacamp.com/courses/deep-learning

http://gluon.mxnet.io

Page 33: Deep Learning with R - earlconf.com · Deep Learning with R Francesca Lazzeri - @frlazzeri Data Scientist II - Microsoft, AI Research

Thank You!Francesca Lazzeri - @frlazzeriData Scientist II - Microsoft, AI Research