Multivariate Linear Regression
This is linear regression, but with multiple variables. So we have a new hypothesis function!
Hypothesis:
Parameters:
Variables:
e.g. Think of each variable as a different feature. could be square footage, could be number of floors, etc.
Gradient Descent for Multiple Variables
Repeat until convergence {
...
}
We can condense this down to:
Gradient Descent Algorithm for Multiple Variables:
Repeat until convergence {
for
}
Gradient Descent with Feature Scaling
Feature scaling speeds up gradient descent and ensures gradient descent to converge.
Let be a feature like age of house.
We generally want the range of the feature to stay in either one of these intervals:
Mean Normalization:
This is a way you can ensure feature scaling ( is range).
Choosing a Learning Rate for Gradient Descent
Debugging Gradient Descent
Plot # of iterations of gradient descent on x-axis and on y-axis.
Automatic convergence test: If is decreasing by less than , most likely has converged (but usually just use a graph because it's easier to see).
Summary:
If is too large → loss function will diverge (yellow line)
If is too small → loss function will converge too slowly (green line).
If is good → loss function will decrease every epoch at a reasonable time.
Creating Features for Polynomial Regression
We don't always have to stick to only having the features in the equation. We can derive more from existing features.
Examples:
Let our hypothesis be
What if we don't want a linear function to fit the data? What if we want a parabola, square root, cubic?
To get a square root function from this:
Let . We have created a new feature ! So now we have: .
Note: Feature scaling is very important here! Imagine if you created a cubic function. Your new feature would then be , so the values would be very large.
Last updated