Linear Regression With Multiple Variables
Linear Regression With Multiple Variables
multiple variables
Multiple features
Machine Learning
Multiple features (variables).
2104 460
1416 232
1534 315
852 178
… …
Andrew Ng
Multiple features (variables).
Size (feet2) Number of Number of Age of home Price ($1000)
bedrooms floors (years)
2104 5 1 45 460
1416 3 2 40 232
1534 3 2 30 315
852 2 1 36 178
… … … … …
Notation:
= number of features
= input (features) of training example.
= value of feature in training example.
Andrew Ng
Hypothesis:
Previously:
Andrew Ng
For convenience of notation, define .
Gradient descent:
Repeat
(simultaneously update )
Andrew Ng
Linear Regression with
multiple variables
Gradient descent in
practice I: Feature Scaling
Machine Learning
Feature Scaling
Idea: Make sure features are on a similar scale.
E.g. = size (0-2000 feet2) size (feet2)
= number of bedrooms (1-5)
number of bedrooms
Andrew Ng
Feature Scaling
Get every feature into approximately a range.
Andrew Ng
Mean normalization
Replace with to make features have approximately zero mean
(Do not apply to ).
E.g.
Andrew Ng
Linear Regression with
multiple variables
Gradient descent in
practice II: Learning rate
Machine Learning
Gradient descent
Andrew Ng
Making sure gradient descent is working correctly.
Example automatic
convergence test:
Declare convergence if
decreases by less than
in one iteration.
0 100 200 300 400
No. of iterations
Andrew Ng
Making sure gradient descent is working correctly.
Gradient descent not working.
Use smaller .
No. of iterations
To choose , try
Andrew Ng