#25 Machine Learning Specialization [Course 1, Week 2, Lesson 2]

DeepLearningAI · Intermediate ·📐 ML Fundamentals ·3y ago

Key Takeaways

This video covers the technique of feature scaling to improve the performance of gradient descent in machine learning, using a concrete example of predicting house prices with two features: size and number of bedrooms.

Full Transcript

so welcome back let's take a look at some techniques that make gradient descents work much better in this video you see a technique called feature scaling that will enable gradient descent to run much faster let's start by taking a look at the relationship between the size of a feature that is how big are the numbers for that feature and the size of its Associated parameter as a concrete example let's predict the price of a house using two features X1 the size of the hulls and X2 the number of bedrooms let's say that X1 typically ranges from 300 to 2000 square feet and x2 in the data set ranges from 0 to 5 bedrooms so for this example X1 takes on a relatively large range of values and X2 takes on a relatively small range of values now let's take an example of a house that has a size of 2 000 square feet has five bedrooms and a price of 500k or 500 000 dollars for this one trading example what do you think are reasonable values for the size of parameters W1 and W2 well let's look at one possible set of parameters say W1 is 50 and W2 is 0.1 and B is 50 for the purposes of discussion so in this case the estimated price in thousands of dollars is 100 000 K here plus 0.5 K plus 50k which is slightly over a hundred million dollars so that's clearly very far from the actual price of five hundred thousand dollars and so this is not a very good set of parameter choices for W1 and W2 now let's take a look at another possibility say W1 and W2 were the other way around W1 is 0.1 and W2 is 50 and B is still also 50. in this choice of W1 and W2 W1 is relatively small and W2 is relatively large 50 is much bigger than 0.1 so here the predicted price is 0.1 times 2 000 plus 50 times 5 plus 50. the first term becomes 200k the second term becomes 250k and then plus 50. so this version of the model predicts a price of five hundred thousand dollars which is a much more reasonable estimate and happens to be the same price as the true price of the house so hopefully you might notice that when a possible range of values of a feature is large like the size in square feet which goes all the way up to 2000 it's more likely that a good model will learn to choose a relatively small parameter value like 0.1 likewise when the possible values of a feature are small like the number of bedrooms then a reasonable value for its parameters will be relatively large like 50. so how does this relate to gradient descent well let's take a look at a scatter plot of the features where the size is square feet is the horizontal axis X1 and the number of bedrooms X2 is on the vertical axis if you plot the training data you notice that the horizontal axis is on a much larger scale or much larger range of values compared to the vertical axis next let's look at how the cost function might look in a contour plot you might see a contour plot where the horizontal axis has a much narrower range say between 0 and 1 whereas the vertical axis takes on much larger values say between 10 and 100. so the Contours form ovals or ellipses and they are short on one side and longer on the other and this is because a very small change to W1 can have a very large impact on the estimated price and thus a very large impact on the cost J because W1 tends to be multiplied by a very large number the size in square feet in contrast it takes a much larger change in W2 in order to change the predictions much and thus small changes to W2 don't change the cost function nearly as much so where does this leave us this is what might end up happening if you were to run gradient descent if you were to use your training data as is because the Contours are still tall and skinny gradient descents may end up bouncing back and forth for a long time before it can finally find its way to the global minimum in situations like this a useful thing to do is to scale the features this means performing some transformation of your training data so that X1 save might not range from 0 to 1 and X2 might also range from 0 to 1. so today the points now look more like this and you might notice that the scale of the plot on the bottom is now quite different than the one on top the key point is that the rescale X1 and X2 are both now taking comparable ranges of values to each other and if you run gradient descent on a cost function defined on this rescaled X1 and X2 using this transform data then the Contours will look more like this more like circles and less tall and skinny and great in descents can find a much more direct path to the global minimum so to recap when you have different features that take on very different ranges of values it can cause gradient descent to run slowly but rescaling the different features so they all take on comparable range of values can speed upgrade and descent significantly how do you actually do this let's take a look at that in the next video

Original Description

The Machine Learning Specialization is a foundational online program created in collaboration between DeepLearning.AI and Stanford Online. This beginner-friendly program will teach you the fundamentals of machine learning and how to use these techniques to build real-world AI applications. This Specialization is taught by Andrew Ng, an AI visionary who has led critical research at Stanford University and groundbreaking work at Google Brain, Baidu, and Landing.AI to advance the AI field. This video is from Course 1 (Supervised Machine Learning Regression and Classification), Week 2 (Regression with multiple input variables), Lesson 2 (Gradient descent in practice), Video 1 (Feature scaling part 1). To learn more and access the full course videos and assignments, enroll in the Machine Learning Specialization here: https://bit.ly/3ERmTAq Download the course slides: https://bit.ly/3AVNHwS Check out all our courses: https://bit.ly/3TTc2KA Subscribe to The Batch, our weekly newsletter: https://bit.ly/3TZUzju Follow us: Facebook: https://www.facebook.com/DeepLearningAIHQ/ LinkedIn: https://www.linkedin.com/company/deeplearningai/ Twitter: https://twitter.com/deeplearningai_
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from DeepLearningAI · DeepLearningAI · 0 of 60

← Previous Next →
1 Forward and Backward Propagation (C1W4L06)
Forward and Backward Propagation (C1W4L06)
DeepLearningAI
2 deeplearning.ai's Heroes of Deep Learning: Yuanqing Lin
deeplearning.ai's Heroes of Deep Learning: Yuanqing Lin
DeepLearningAI
3 deeplearning.ai's Heroes of Deep Learning: Ruslan Salakhutdinov
deeplearning.ai's Heroes of Deep Learning: Ruslan Salakhutdinov
DeepLearningAI
4 deeplearning.ai's Heroes of Deep Learning: Yoshua Bengio
deeplearning.ai's Heroes of Deep Learning: Yoshua Bengio
DeepLearningAI
5 deeplearning.ai's Heroes of Deep Learning: Pieter Abbeel
deeplearning.ai's Heroes of Deep Learning: Pieter Abbeel
DeepLearningAI
6 deeplearning.ai's Heroes of Deep Learning: Ian Goodfellow
deeplearning.ai's Heroes of Deep Learning: Ian Goodfellow
DeepLearningAI
7 deeplearning.ai's Heroes of Deep Learning: Andrej Karpathy
deeplearning.ai's Heroes of Deep Learning: Andrej Karpathy
DeepLearningAI
8 Using an Appropriate Scale (C2W3L02)
Using an Appropriate Scale (C2W3L02)
DeepLearningAI
9 Gradient Checking (C2W1L13)
Gradient Checking (C2W1L13)
DeepLearningAI
10 Gradient Checking Implementation Notes (C2W1L14)
Gradient Checking Implementation Notes (C2W1L14)
DeepLearningAI
11 Learning Rate Decay (C2W2L09)
Learning Rate Decay (C2W2L09)
DeepLearningAI
12 Understanding Mini-Batch Gradient Dexcent (C2W2L02)
Understanding Mini-Batch Gradient Dexcent (C2W2L02)
DeepLearningAI
13 Mini Batch Gradient Descent (C2W2L01)
Mini Batch Gradient Descent (C2W2L01)
DeepLearningAI
14 The Problem of Local Optima (C2W3L10)
The Problem of Local Optima (C2W3L10)
DeepLearningAI
15 Exponentially Weighted Averages (C2W2L03)
Exponentially Weighted Averages (C2W2L03)
DeepLearningAI
16 Tuning Process (C2W3L01)
Tuning Process (C2W3L01)
DeepLearningAI
17 Understanding Exponentially Weighted Averages (C2W2L04)
Understanding Exponentially Weighted Averages (C2W2L04)
DeepLearningAI
18 Bias Correction of Exponentially Weighted Averages (C2W2L05)
Bias Correction of Exponentially Weighted Averages (C2W2L05)
DeepLearningAI
19 Gradient Descent With Momentum (C2W2L06)
Gradient Descent With Momentum (C2W2L06)
DeepLearningAI
20 Normalizing Activations in a Network (C2W3L04)
Normalizing Activations in a Network (C2W3L04)
DeepLearningAI
21 Hyperparameter Tuning in Practice (C2W3L03)
Hyperparameter Tuning in Practice (C2W3L03)
DeepLearningAI
22 Adam Optimization Algorithm (C2W2L08)
Adam Optimization Algorithm (C2W2L08)
DeepLearningAI
23 RMSProp (C2W2L07)
RMSProp (C2W2L07)
DeepLearningAI
24 Fitting Batch Norm Into Neural Networks (C2W3L05)
Fitting Batch Norm Into Neural Networks (C2W3L05)
DeepLearningAI
25 Why Does Batch Norm Work? (C2W3L06)
Why Does Batch Norm Work? (C2W3L06)
DeepLearningAI
26 Batch Norm At Test Time (C2W3L07)
Batch Norm At Test Time (C2W3L07)
DeepLearningAI
27 Softmax Regression (C2W3L08)
Softmax Regression (C2W3L08)
DeepLearningAI
28 Deep Learning Frameworks (C2W3L10)
Deep Learning Frameworks (C2W3L10)
DeepLearningAI
29 Neural Network Overview (C1W3L01)
Neural Network Overview (C1W3L01)
DeepLearningAI
30 Training Softmax Classifier (C2W3L09)
Training Softmax Classifier (C2W3L09)
DeepLearningAI
31 Why Deep Representations? (C1W4L04)
Why Deep Representations? (C1W4L04)
DeepLearningAI
32 Gradient Descent For Neural Networks (C1W3L09)
Gradient Descent For Neural Networks (C1W3L09)
DeepLearningAI
33 Neural Network Representations (C1W3L02)
Neural Network Representations (C1W3L02)
DeepLearningAI
34 TensorFlow (C2W3L11)
TensorFlow (C2W3L11)
DeepLearningAI
35 Activation Functions (C1W3L06)
Activation Functions (C1W3L06)
DeepLearningAI
36 Explanation For Vectorized Implementation (C1W3L05)
Explanation For Vectorized Implementation (C1W3L05)
DeepLearningAI
37 Getting Matrix Dimensions Right (C1W4L03)
Getting Matrix Dimensions Right (C1W4L03)
DeepLearningAI
38 Understanding Dropout (C2W1L07)
Understanding Dropout (C2W1L07)
DeepLearningAI
39 Building Blocks of a Deep Neural Network (C1W4L05)
Building Blocks of a Deep Neural Network (C1W4L05)
DeepLearningAI
40 Why Non-linear Activation Functions (C1W3L07)
Why Non-linear Activation Functions (C1W3L07)
DeepLearningAI
41 Computing Neural Network Output (C1W3L03)
Computing Neural Network Output (C1W3L03)
DeepLearningAI
42 Backpropagation Intuition (C1W3L10)
Backpropagation Intuition (C1W3L10)
DeepLearningAI
43 Train/Dev/Test Sets (C2W1L01)
Train/Dev/Test Sets (C2W1L01)
DeepLearningAI
44 Deep L-Layer Neural Network (C1W4L01)
Deep L-Layer Neural Network (C1W4L01)
DeepLearningAI
45 Random Initialization (C1W3L11)
Random Initialization (C1W3L11)
DeepLearningAI
46 Other Regularization Methods (C2W1L08)
Other Regularization Methods (C2W1L08)
DeepLearningAI
47 Normalizing Inputs (C2W1L09)
Normalizing Inputs (C2W1L09)
DeepLearningAI
48 Derivatives Of Activation Functions (C1W3L08)
Derivatives Of Activation Functions (C1W3L08)
DeepLearningAI
49 Parameters vs Hyperparameters (C1W4L07)
Parameters vs Hyperparameters (C1W4L07)
DeepLearningAI
50 Vectorizing Across Multiple Examples (C1W3L04)
Vectorizing Across Multiple Examples (C1W3L04)
DeepLearningAI
51 What does this have to do with the brain? (C1W4L08)
What does this have to do with the brain? (C1W4L08)
DeepLearningAI
52 Dropout Regularization (C2W1L06)
Dropout Regularization (C2W1L06)
DeepLearningAI
53 Vanishing/Exploding Gradients (C2W1L10)
Vanishing/Exploding Gradients (C2W1L10)
DeepLearningAI
54 Basic Recipe for Machine Learning (C2W1L03)
Basic Recipe for Machine Learning (C2W1L03)
DeepLearningAI
55 Bias/Variance (C2W1L02)
Bias/Variance (C2W1L02)
DeepLearningAI
56 Forward Propagation in a Deep Network (C1W4L02)
Forward Propagation in a Deep Network (C1W4L02)
DeepLearningAI
57 Weight Initialization in a Deep Network (C2W1L11)
Weight Initialization in a Deep Network (C2W1L11)
DeepLearningAI
58 Numerical Approximations of Gradients (C2W1L12)
Numerical Approximations of Gradients (C2W1L12)
DeepLearningAI
59 Regularization (C2W1L04)
Regularization (C2W1L04)
DeepLearningAI
60 Why Regularization Reduces Overfitting (C2W1L05)
Why Regularization Reduces Overfitting (C2W1L05)
DeepLearningAI

This video teaches the importance of feature scaling in machine learning to improve the performance of gradient descent, and how to apply it to a concrete example of predicting house prices.

Key Takeaways
  1. Identify features with different ranges of values
  2. Apply feature scaling to transform the data
  3. Visualize the cost function using a contour plot
  4. Run gradient descent on the rescaled data
  5. Compare the results with the original data
💡 Feature scaling can significantly speed up gradient descent by making the cost function contours more circular and less tall and skinny.

Related Reads

📰
Mixture of Experts Is Not an Efficiency Trick — It’s a Systems Philosophy
Mixture of Experts is a systems philosophy that goes beyond efficiency tricks, enabling more effective and scalable AI systems
Medium · Machine Learning
📰
Explainable Causal Reinforcement Learning for autonomous urban air mobility routing under real-time policy constraints
Learn how Explainable Causal Reinforcement Learning can optimize autonomous urban air mobility routing under real-time policy constraints
Dev.to AI
📰
5 ARB and ICU edge cases I wish I'd tested earlier
Learn from common edge cases in ARB and ICU to improve localization testing
Dev.to · Evgenii Sokolov
📰
RQLM Part 3: The Instruction Pointer Was Already There
Learn about the concept of a synchronous quantum-hybrid machine and its implementation using a six-address quantum microcode sequencer
Medium · Machine Learning
Up next
The Adam Optimizer is Just Momentum + RMSProp
DataMListic
Watch →