Machine Learning Wu Enda3

chapter 27 Multiple features

start to talk about a new version of linear regression,more powerful one that works with multiple variables or with multiple features.

Machine Learning Wu Enda3

Notation:

n = number of features

x(i) = input (features) of i th training example.

xj(i) = value of feature j in i th training example.

Hypothesis:

hθ(x)=θ0+θ1x1+θ2x2+...+θnxn

for convenience of notation ,define x0 = 1.

x=[x0x1x2xn]Rn+1        

θ=[θ0θ1θ2θn]Rn+1

so

hθ(x)=θTx

Multivariate linear regression.

chapter 28 Gradient descent for multiple variables

how to fit the parameters of that hypothesis.how to use gradient descent for linear regression with multiple features

Hypothesis: hθ(x)=θTx=θ0x0+θ1x1+...+θnxn)

Parameters: θ here is a n+1-dimensional vector.

Cost function:

J(θ)=12mi=1m(hθ(x(i))y(i))

Gradient descent:

​ Repeat{

θj:=θjaθjJ(θ)

​ } (simultaneously update for every j=0,...,n)

New algorithm(n>=1):

Repeat{

θj:=θja1mi=1m(hθ(x(i))y(i))

}

θ0:=θ0a1mi=1m(hθ(x(i))y(i))x0(i)

θ1:=θ1a1mi=1m(hθ(x(i))y(i))x1(i)

chapter 29 Gradient descent in practice 1:feature scaling

practical tricks for making gradient descent work well

Feature Scaling:

Idea: Make sure features are on similar scale.

Machine Learning Wu Enda3

Get every feature into approximately a 1<=xi<=1 range.

Mean normalization

Replace xi with xiui to make features have approximately zero mean (Do not apply to x0=1)

x1x1u1s1 u1 is the average value of x1 in the training sets.

s1 is the range of values of that feature or standard deviation

chapter 30 Gradient descent in practice 2:learning rate

around the learning rate a

  • “Debugging “:How to make sure gradient descent is working correctly.
  • How to choose learning rate a

Machine Learning Wu Enda3

Declare convergence if J(θ) decreases by less than 103 in one iteration.

but choose what this threshold is pretty difficult.So,in order to check your gradient descent has converged, actually tend to look at plots.

Machine Learning Wu Enda3

  • For sufficiently small a ,J(θ)should decrease on every iteration.
  • But if a is too small,gradient descent can be slow to converge.
  • if a is too large ;J(θ) may not decrease on every iteration ;may not converge.

chapter 31 Features and polynomial regression

the choice of features that you have and how you can get different learning algorithm

Machine Learning Wu Enda3

It is important to apply feature scaling if you’re using gradient descent to get them into comparable ranges of values.

broad choices in the features you use.

Machine Learning Wu Enda3

chapter 32 Normal equation

which for some linear regression problems ,will give us a much better way to solve for the optimal value of the parameters θ

Normal equation : Method to solve for θ analytically.

Machine Learning Wu Enda3

Machine Learning Wu Enda3

正规方程推到过程:https://zhuanlan.zhihu.com/p/22474562

矩阵求导:https://blog.****.net/nomadlx53/article/details/50849941

Gradient Descent and Normal Equation advantages and disadvantages :

Machine Learning Wu Enda3

The normal equation method actually do not work for those more sophisticated learning algorithms.

chapter 33 Normal equation and non-invertibility (optional)

what if XTX is non-invertible?

  • Redundant features (linearly dependent)

e g : x1 = size in feet2 x2 = size in m2

  • too many features (e.g m<=n)

Delete some features , or use regularization.