Top Banner
Building a Neural Network from scratch in R Owen Jones Bath Machine Learning Meetup 1 st March 2017
58

Building a Neural Network from scratch in R

Apr 12, 2017

Download

Technology

Owen Jones
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: Building a Neural Network from scratch in R

Building a Neural Network from scratch

in ROwen Jones ∙ Bath Machine Learning Meetup 1∙ st March 2017

Page 2: Building a Neural Network from scratch in R

What is the most important network we’ll be using tonight?

Page 3: Building a Neural Network from scratch in R

Building a Social Network from scratch

in BMLMOwen Jones ∙ Bath Machine Learning Meetup 1∙ st March 2017

Page 4: Building a Neural Network from scratch in R

What’s a neural network?

Page 5: Building a Neural Network from scratch in R

What’s a neural network?

This is a dog

This is a dog

This is a cat

This is a dog

This is a cat

This is a cat

This is a dog

OK.

Page 6: Building a Neural Network from scratch in R

What’s a neural network?

Dog!

What is this?

Page 7: Building a Neural Network from scratch in R

Data

Kaggle competition page• https://kaggle.com/c/digit-recognizer

Data• https://kaggle.com/c/digit-recognizer/data

Page 8: Building a Neural Network from scratch in R

What are these numbers?

Page 9: Building a Neural Network from scratch in R

What are these numbers?

0 60 140 200 255

0 60 140 200 255

0 60 140 200 255

0 60 140 200 255

0 60 140 200 255

Page 10: Building a Neural Network from scratch in R

What are these numbers?

0 60 140 200 255

0 60 140 200 255

0 60 140 200 255

0 60 140 200 255

0 60 140 200 255

Page 11: Building a Neural Network from scratch in R

What are these numbers?

0 60 140 200 255 0 60 140 200 255 0 60 140 200 255 0 60 140 200 255 0 60 140 200 255

Page 12: Building a Neural Network from scratch in R

Why relabel 0?

0 1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9 10

Zero-indexed

One-indexed

1st 2nd 3rd

Page 13: Building a Neural Network from scratch in R

Why relabel 0?

0 1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9 10

Zero-indexed

One-indexed

1st 2nd 3rd

Page 14: Building a Neural Network from scratch in R

Why relabel 0?

0 1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9 10

Zero-indexed

One-indexed

1st 2nd 3rd

0 0 1 0 0 0 0 0 0 03

Page 15: Building a Neural Network from scratch in R

Making sets

Everything!

100%

Page 16: Building a Neural Network from scratch in R

Making sets

Cross-validation set

20%

Test set

20%

Training set

60%

Page 17: Building a Neural Network from scratch in R

How does the net make predictions?

Page 18: Building a Neural Network from scratch in R

How does the net make predictions?

Page 19: Building a Neural Network from scratch in R

How does the net make predictions?

Page 20: Building a Neural Network from scratch in R

How does the net make predictions?

Page 21: Building a Neural Network from scratch in R

How does the net make predictions?

Sum = 1000 Sum = 300 Sum = 800

Page 22: Building a Neural Network from scratch in R

Network structure

Page 23: Building a Neural Network from scratch in R

Network structure

Page 24: Building a Neural Network from scratch in R

Network structure

Page 25: Building a Neural Network from scratch in R

Network structure

Page 26: Building a Neural Network from scratch in R

Matrices

Page 27: Building a Neural Network from scratch in R

Matrices

Page 28: Building a Neural Network from scratch in R

Biological neuron

Page 29: Building a Neural Network from scratch in R

Biological neuron

Page 30: Building a Neural Network from scratch in R

Biological neuron

Page 31: Building a Neural Network from scratch in R

Activation functions

Page 32: Building a Neural Network from scratch in R

Activation functions

Page 33: Building a Neural Network from scratch in R

Network structure

Page 34: Building a Neural Network from scratch in R

How wrong were we?Prediction (A3)

Actual 0 0 0 0 0 0 0 0 1 0

0.08 0.31 0.85 0.37 0.43 0.51 0.12 0.54 0.71 0.42

-log(A3) * Actual 0 0 0 0 0 0 0 0 0.34 0

Page 35: Building a Neural Network from scratch in R

How wrong were we?Prediction (A3)

Actual 0 0 0 0 0 0 0 0 1 0

0.08 0.31 0.85 0.37 0.43 0.51 0.12 0.54 0.71 0.42

1 1 1 1 1 1 1 1 0 11 - Actual

-log(A3) * Actual 0 0 0 0 0 0 0 0 0.34 0

0.08 0.37 1.90 0.46 0.56 0.71 0.13 0.78 0 0.54-log(1 - A3) * (1 - Actual)

0.92 0.69 0.15 0.63 0.57 0.49 0.88 0.46 0.29 0.581 - A3

Page 36: Building a Neural Network from scratch in R

How wrong were we?Prediction (A3)

Actual 0 0 0 0 0 0 0 0 1 0

0.08 0.31 0.85 0.37 0.43 0.51 0.12 0.54 0.71 0.42

1 1 1 1 1 1 1 1 0 11 - Actual

-log(A3) * Actual 0 0 0 0 0 0 0 0 0.34 0

0.08 0.37 1.90 0.46 0.56 0.71 0.13 0.78 0 0.54-log(1 - A3) * (1 - Actual)

0.92 0.69 0.15 0.63 0.57 0.49 0.88 0.46 0.29 0.581 - A3

Cost (J) = 0.34 + 0.08 + 0.37 + 1.90 + 0.46 + 0.56 + 0.71 + 0.13 + 0.78 + 0.54 = 5.87

Page 37: Building a Neural Network from scratch in R

Multilayer perceptron

Page 38: Building a Neural Network from scratch in R

Convolutional neural networks

Page 39: Building a Neural Network from scratch in R

Recurrent neural networks

Page 40: Building a Neural Network from scratch in R

Recurrent neural networks

Page 41: Building a Neural Network from scratch in R

Learning from experience

This is a dog

This is a dog

This is a cat

This is a dog

This is a cat

This is a cat

This is a dog

OK.

Page 42: Building a Neural Network from scratch in R

Learning from experience

Dog!

What is this?

Page 43: Building a Neural Network from scratch in R

Learning from experience

Cat!

What is this?

Page 44: Building a Neural Network from scratch in R

Learning from experience

Dog?

What is this?

Page 45: Building a Neural Network from scratch in R

Learning from experience

Cat???

What is this?

Page 46: Building a Neural Network from scratch in R

Learning from experienceWhat even

is that?

What comes next?

Once upon a

Page 47: Building a Neural Network from scratch in R

General intelligence

https://arxiv.org/pdf/1411.4555.pdf

Page 48: Building a Neural Network from scratch in R

General intelligence

Page 49: Building a Neural Network from scratch in R
Page 50: Building a Neural Network from scratch in R

Backpropagation

Page 51: Building a Neural Network from scratch in R

Backpropagation

Page 52: Building a Neural Network from scratch in R

Backpropagation

Page 53: Building a Neural Network from scratch in R

Backpropagation

Page 54: Building a Neural Network from scratch in R

Backpropagation

Page 55: Building a Neural Network from scratch in R

Backpropagation

Page 56: Building a Neural Network from scratch in R

Backpropagation

Page 57: Building a Neural Network from scratch in R

Backpropagation

Page 58: Building a Neural Network from scratch in R

Contact me

Website: https://owenjonesuob.github.io

Email: [email protected]

Twitter: @owenjonesuob

GitHub: https://github.com/owenjonesuob

LinkedIn: https://uk.linkedin.com/in/owenjonesuob

• https://uk.linkedin.com/in/owenjonesuob