Regularization in a Neural Network explained
Key Takeaways
This video explains the concept of regularization in artificial neural networks, specifically L2 regularization, and demonstrates how to implement it in Keras.
Full Transcript
[Music] in this video we'll discuss what regularization is and when and why it may be helpful to add it to our model in our previous video on overfitting we briefly introduce the concept of dropout and stated that it was a regularization technique we haven't yet discussed what regularization is so let's do that now in general regularization is a technique that helps reduce overfitting or reduce variance in our network by penalizing for complexity the idea is that certain complexities in our model may make our model unlikely to generalize well even though it fits the training data so given this if we add regularization to our model we're essentially trading in some of the ability of our model to fit the training data well for the ability to have the model generalize better to data it hasn't seen before to implement regularization is to simply add a term to our loss function that penalizes for large weights we'll expand on this idea in just a moment the most common regularization technique is called l2 regularization now we just said that regularization basically involves adding a term to our loss function that penalizes for large weights with l2 regularization the term that we're adding to the loss is the sum of the squared norms of the weight matrices multiplied by a small constant now if you're not familiar with norms in general understand that a norm is just a function that assigns a strictly positive length or size to each vector in a vector space the vector space we're working with here would just depend on the size of our weight matrices rather than going on a linear algebra tangent about norms in this moment we'll continue on with the general idea about regularization but given that norms are a fundamental concept of linear algebra there's a lot of information available on the web that explains norms in detail if you need to get a better grasp but to oversimplify know that for now the norm of each of our weight matrices is just going to be a positive number so let's break down l2 regularization we have our loss function here now we add the sum of the squared norms from our weight matrices and multiply this by a constant this constant here is going to be denoted by lambda divided by 2 M where m is the number of inputs now this lambda here is called the regularization parameter and this is another hyper parameter that we'll have to choose and then test in tune in order to assign the correct number for our specific model so to summarize we know that regularization is just a technique that penalizes for relatively large weights in our model and behind the scenes the implementation of regularization is just the addition of a term to our existing loss function with l2 regularization we saw that this term is the sum of the squared norms of our weight matrices that is then added to the regularization parameter lambda divided by 2 times our input so why does regularization help well using l2 regularization as an example if we were to set lambda to be a relatively large number then it would incentivize the model to set the weights close to 0 because the objective of SGD is to minimize the loss function and remember our original loss function is now being summed with the sum of the squared matrix norms which is then being multiplied by lambda over 2m so if lambda was large then this term here would continue to stay relatively large and if we're multiplying that by this sum then that product may be relatively large depending on how large our weights are so then our model is incentivized to make these weights small so that the value of the overall function stays relatively small in order to meet the objective of minimizing the loss intuitively we could think that maybe this technique will set the weights so close to zero that it could basically zero out or reduce the impact of some of our layers in that case it would conceptually simplify our model making our model less complex which may in turn reduce variance and overfitting so now that we have a general idea about regularization let's see how we can add it to our model and caris so I'm here on my jupiter notebook and in this first cell i've just imported the libraries and classes that we'll be working with the only one that should be new to us is this last one here i'm importing regularizer x' from Charis now one thing dementia here is that regularizer Xin Karis allow us to apply penalties on layer parameters or layer activity during optimisation so we're essentially setting regularization for specific layers rather than for the entire model in this next cell I have a model we've worked with in previous videos for all intensive purposes this model is pretty arbitrary we've got two dense layers with 16 and 32 nodes respectively with both using r lu and an output layer with two nodes for classification using the sigmoid activation function now there's only one difference in this model from how it was in other videos that we've seen it in the difference here is within our second hidden layer that has 32 nodes I've added this kernel underscore regularizer parameter here I'm specifying that I want to use l2 regularization by setting the parameter equal to regularize errs l2 I'm then specifying point 0 1 to be the regularization parameter which we denoted earlier as lambda and that really is all there is to it for adding regularization to one of our layers and caris so hopefully now you have a general idea about what regularization is and how it can help reduce overfitting additionally you should now know how to apply it in Kerris as well so I hope you found this video helpful if you did please like the video subscribe suggest and comment and thanks for watching you
Original Description
In this video, we explain the concept of regularization in an artificial neural network and also show how to specify regularization in code with Keras.
🕒🦎 VIDEO SECTIONS 🦎🕒
00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources
00:30 Help deeplizard add video timestamps - See example in the description
05:25 Collective Intelligence and the DEEPLIZARD HIVEMIND
💥🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎💥
👋 Hey, we're Chris and Mandy, the creators of deeplizard!
👀 CHECK OUT OUR VLOG:
🔗 https://youtube.com/deeplizardvlog
👉 Check out the blog post and other resources for this video:
🔗 https://deeplizard.com/learn/video/iuJgyiS7BKM
💻 DOWNLOAD ACCESS TO CODE FILES
🤖 Available for members of the deeplizard hivemind:
🔗 https://deeplizard.com/resources
🧠 Support collective intelligence, join the deeplizard hivemind:
🔗 https://deeplizard.com/hivemind
🤜 Support collective intelligence, create a quiz question for this video:
🔗 https://deeplizard.com/create-quiz-question
🚀 Boost collective intelligence by sharing this video on social media!
❤️🦎 Special thanks to the following polymaths of the deeplizard hivemind:
Tammy
Prash
Zach Wimpee
👀 Follow deeplizard:
Our vlog: https://youtube.com/deeplizardvlog
Facebook: https://facebook.com/deeplizard
Instagram: https://instagram.com/deeplizard
Twitter: https://twitter.com/deeplizard
Patreon: https://patreon.com/deeplizard
YouTube: https://youtube.com/deeplizard
🎓 Deep Learning with deeplizard:
Fundamental Concepts - https://deeplizard.com/learn/video/gZmobeGL0Yg
Beginner Code - https://deeplizard.com/learn/video/RznKVRTFkBY
Intermediate Code - https://deeplizard.com/learn/video/v5cngxo4mIg
Advanced Deep RL - https://deeplizard.com/learn/video/nyjbcRQ-uQ8
🎓 Other Courses:
Data Science - https://deeplizard.com/learn/video/d11chG7Z-xk
Trading - https://deeplizard.com/learn/video/ZpfCK_uHL9Y
🛒 Check out products deeplizard recommends on Amazon:
🔗 https://amazon.com/shop/deeplizard
📕 Get
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from deeplizard · deeplizard · 59 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
▶
60
Install Jaxx cryptocurrency wallet on Windows 10 and verify file hash
deeplizard
Jaxx cryptocurrency wallet overview - A Blockchain Interface
deeplizard
Remove Jaxx cryptocurrency wallet from Windows 10
deeplizard
Install Jaxx cryptocurrency wallet Chrome extension
deeplizard
Send Litecoin from GDAX to Jaxx wallet
deeplizard
Send Litecoin from Jaxx wallet to GDAX
deeplizard
Backup and restore Jaxx wallet with passphrase
deeplizard
Send Litecoin to Bittrex using Jaxx and monitor confirmations with BlockCypher
deeplizard
Join a mining pool on Waves platform and lease Waves
deeplizard
ZCASH Explained | An introduction to a privacy based cryptocurrency
deeplizard
ZCash t address creation with Jaxx wallet and private key blockchain discussion
deeplizard
Buy ZCash with Litecoin using the Shifty button in the Jaxx wallet
deeplizard
Buy ZCash with Litecoin using ShapeShift - FAILURE
deeplizard
Litecoin | Jaxx | Shapeshift | zcash | failed
deeplizard
Buy ZCash with Litecoin using ShapeShift - SUCCESS even with Jaxx issues
deeplizard
Explore ZCash blockchain with Zchain block explorer
deeplizard
Zchain ZCash block explorer API - PowerShell Code
deeplizard
Zchain ZCash block explorer API - Introduction
deeplizard
Zchain ZCash block explorer API - Application
deeplizard
Coinbase's Trading Platform | Previously known as GDAX
deeplizard
Coinbase Social Security Number (SSN) Requirement Explained
deeplizard
Who owns Coinbase? Here are some KEY people
deeplizard
How does Coinbase/GDAX secure Bitcoin, Litecoin, Ether?
deeplizard
Coinbase | HackerOne bug bounty program
deeplizard
Is Bitcoin safe at Coinbase/GDAX?
deeplizard
Coinbase Login Demo Using Google Authenticator (2FA)
deeplizard
Coinbase Pro - GDAX | Trading Interface Overview
deeplizard
Coinbase gives $10 in Bitcoin | Watch this before signing up
deeplizard
Coinbase around the globe | What countries are supported?
deeplizard
Order book explained | Trading concept to know
deeplizard
Bid/Ask spread explained | Trading concept to know
deeplizard
Maker vs Taker | Trading concept to know
deeplizard
Market Orders are Always TAKERS (HIGHER FEES)!
deeplizard
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 1
deeplizard
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 2
deeplizard
Time-in-force explained | Trading concept to know
deeplizard
Stop order explained | How to stop a loss | Coinbase Pro - GDAX
deeplizard
Stop Order on Coinbase Pro - GDAX | What the WARNINGS Mean
deeplizard
Market price vs Last price | Trading concept to know
deeplizard
Stop Order on Coinbase Pro - GDAX | How it is ACTIVATED
deeplizard
Stop-limit order | How to set the limit | Coinbase Pro - GDAX
deeplizard
Flash CRASH Part 1 | ETH/USD currency pair traded at $0.10
deeplizard
Slippage explained | Trading concept to know
deeplizard
Flash CRASH Part 2 | How did Coinbase Respond?
deeplizard
Buy side stop-limit order | Crypto trading strategy for buying a breakout
deeplizard
Buy side stop-limit order | Triggering under the market price
deeplizard
What is an order book?
deeplizard
What is a market?
deeplizard
What is an exchange?
deeplizard
What is a broker-dealer?
deeplizard
Keras prerequisites
deeplizard
Change Keras backend to Theano
deeplizard
#1 Order types and parameters | Trading on Coinbase Pro - GDAX
deeplizard
Trading strategy for stopping a loss | Don't trade all at once!
deeplizard
#2 Order matching engine | Trading on Coinbase Pro - GDAX
deeplizard
Batch Size in a Neural Network explained
deeplizard
Deep Learning playlist overview & Machine Learning intro
deeplizard
Artificial Neural Networks explained
deeplizard
Regularization in a Neural Network explained
deeplizard
Create confusion matrix for predictions from Keras model
deeplizard
More on: Neural Network Basics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Want to get started with deep learning
Reddit r/deeplearning
Building a Deepfake Detector From Scratch — What Nobody Tells You
Medium · Deep Learning
Unfolding the Meandering Path: High-Dimensional Invariance and the Flat 2D Plane of Neural…
Medium · Deep Learning
Implementing Neural Style Transfer from Scratch: The Project That Started It All
Medium · Deep Learning
Chapters (3)
Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources
0:30
Help deeplizard add video timestamps - See example in the description
5:25
Collective Intelligence and the DEEPLIZARD HIVEMIND
🎓
Tutor Explanation
DeepCamp AI