Multiple features
Multiple features
Notation:
- n = number of features
-
= input (features) of
training example.
-
= value of feature j in
training example.
For convenience of notation, define
向量内积
Multivariate linear regression
Gradient descent for multiple variables
Hypothesis:
Parameters: (a n+1 dimensional vector)
Cost function:
Gradient descent:
Repeat {
}
Feature Scaling
Idea:Make sure features are on a similar scale
一般认为在就可以认为是可以的
Feature Scaling:Get every feature into approximately a range.
Mean normalization:Replace with
to make features have approximately zero mean.(Do not apply to
)
Learning rate
- Make sure gradient descent is working correctly.
should decrease on every iteration.But if
is too small, gradient descent can be slow to converge.
Features and Polynomial Regression
Normal Equation
Normal equation: Method to solve for ananlytically.
Octave:pinv(x'*x)*x'*y
m training examples, n features
Gradient Descent
- Need to choose
- Needs many iterations
- Works well even when n is large
Normal Equation
- No need to choose
- Don't need to iterate
- Need to compute
- Slow if
is very large(less than 10000)
Normal Equation Nonivertibility (Optional)
What if is non-invertible?
- Redundant features (linearly dependent)
- Too many features(e.g.
)
这种情况极少出现