1 of 28

Closing

Ceremony

Project: Baseline Model

Presentations

Project work

Project: Advanced Model (Upgrade from Baseline)

Week 6

Week 7

Week 8

Week 9

Week 10

Convolutional Neural Networks (CNNs)

Tools for Improving CNNs: Regularization and Transfer Learning

Image Classification with CNNs

Ethics in AI

Advanced Topics in Image Classification: Using VGG16

Project work

Project work

Tuning Neural Networks (Classification)

Project: Start Projects with EDA!

Tuning NNs, Using NNs for classification, Validation Sets

2 of 28

Overfitting & Underfitting

Quick Review

3 of 28

A

B

C

Train MSE: 7.54

Test MSE: 7.78

Train MSE: 0

Test MSE: 3.45

Train MSE: 2.81

Test MSE: 2.94

Best Predictions!

4 of 28

A

B

C

If model is too simple, we underfit.

If model is too complex, we overfit to the training data.

Model is well-tuned. Complex enough to capture the trend, but simple enough to prevent overfitting.

5 of 28

Neural Networks

Quick Review

6 of 28

How to train a neural network

Step 1: Set weights randomly

Price

-25

80

10

120

4

Size: 1800 ft^2

Number of Bedrooms: 2

Rating of Local Schools): 75

Repairs Needed ($): $2,000

Bias Term

7 of 28

How to train a neural network

Step 2: Forward pass to get prediction

Price

-25

80

10

120

4

Size: 1800 ft^2

Number of Bedrooms: 2

Rating of Local Schools): 75

Repairs Needed ($): $2,000

Bias Term

1800(-25) + 2(80) + 75(10) + 2000(120) + 4 = $195,914

8 of 28

How to train a neural network

Step 3: Calculate loss by comparing prediction vs. actual

Price

-25

80

10

120

4

Size: 1800 ft^2

Number of Bedrooms: 2

Rating of Local Schools): 75

Repairs Needed ($): $2,000

Bias Term

Terrible prediction!

Residual = Actual - Predicted

Residual = 780,000 - 195,914

Residual = 584,086

1800(-25) + 2(80) + 75(10) + 2000(120) + 4 = $195,914

9 of 28

How to train a neural network: Gradient Descent

Step 4: Backpropagate to adjust weights to lower loss

Price

-25

80

10

120

4

Size: 1800 ft^2

Number of Bedrooms: 2

Rating of Local Schools): 75

Repairs Needed ($): $2,000

Bias Term

“If I had increased this weight, I would have had less error (lower MSE).”

10 of 28

How to train a neural network:

Step 5: Repeat steps 2-4 for your whole dataset, many times. Repeat until reach desired accuracy.

  • Step 2: Forward pass to get prediction
  • Step 3: Calculate loss by comparing prediction vs. actual
  • Step 4: Backpropagate to adjust weights to lower loss

11 of 28

Remember:

From many small dumb things → one big smart thing

12 of 28

Tuning Neural Networks (& using them for classifications

Week 6

13 of 28

Using NN’s for classifications

Part 1

14 of 28

So far, we’ve used Neural Networks for Regression:

  • Predicting a quantitative outcome, like price of a home

We can also use Neural Networks for Classification:

  • Predicting a categorical outcome, like the outcome of a soccer match

15 of 28

3 Outcomes

Win

Draw

Lose

16 of 28

Neural Network for Classification

Inputs

Hidden Layers

Outputs

Team Record

Player Ratings

Field Weather

Last Match Result

Home/Away

Chat Waterfall: Why 3 nodes in output layer?

17 of 28

Neural Network for Classification

Inputs

Hidden Layers

Outputs

Team Record

Player Ratings

Field Weather

Last Match Result

Home/Away

Probability of each outcome

P(Win)

P(Draw)

P(Lose)

18 of 28

Neural Network for Classification

Outputs

Probability of each outcome

Use softmax activation function to bound outputs between 0 - 1.

19 of 28

Note: For regression tasks (e.g. predicting price of home), only 1 output node

Predicted price

20 of 28

Tuning Neural Networks

Part 2

21 of 28

Ok, so you’ve built a neural network!

Now, how do we make it great?

22 of 28

Ok, so you’ve built a neural network!

Now, how do we make it great?

We make it well-tuned! But instead of adjusting polynomial terms (like above), we’ll adjust…

23 of 28

Things to tune on a neural network…

Note: There are many more things we could tune, but we’re focusing on the above for this course

Depth (Number of Layers)

Width (Number of Nodes per Layer)

24 of 28

Different choices → Different model complexity

VS.

Chat Waterfall: What is the danger of making our networks extremely complex?

25 of 28

Problem: Can’t use just one test set. May want to make many adjustments after trials on multiple test sets. Might run out of data for a true test…

26 of 28

Solution: Validation Set!

We need to add a validation set! (explanation on next slide)

27 of 28

While tuning

Fit model on this data

Test model on this data

Repeat until find best model architecture.

Try out:

1 layer, 20 nodes

2 layers, 20 nodes

3 layers, 20 nodes

1 layer, 30 nodes

2 layers, 30 nodes …

28 of 28

Evaluate model predictions on unseen test data (final prediction)

Fit optimal model architecture all this data (final model)

Once you’ve decided the optimal architecture (e.g. 3 layers, 20 nodes)...