机器学习笔记-1 Linear Regression with Multiple Variables(week 2)

 

1. Multiple Features

note:X0 is equal to 1

 

2. Feature Scaling

Idea: make sure features are on a similiar scale, approximately a -1<Xi<1 range

For example:

x1 = size (0-2000 feet^2) max-min or standard deviation

x2 = number of bedrooms(1-5)

The contour function of theta1 and theat2 is a very skewed elliptical shape. And 

if you are running gradient descent on this, your gradients may end up a long time

to fjnd the global minimum.

Cure:

x1 = size (0-5000 feet^2)/2000

x2 = number of bedrooms(1-5)/5

so the coutour plots will give a much more direct path to the minimum

Mean normalization:

Replace Xwith Xi  -  Ui  to make features have zero mean(except X0)

Eg:

X1 = (size-1000)/2000

X2= (#bedrooms-2)/5

 

3. Learning Rate

We can plot the J(theata) vs number of iterations and the J(theata) should

decrease after every iteraion. and we can also see if the gradient descent converges or not.

And if gradient descent is not working, usually means that:

you should use a smaller value of alpha(learning rate)

To choose alpha():

..., 0.001, 0.003, 0.01, 0.03, 0.1, 0.3, 1...

 

4. Features

you can try to define new features, for example:

Area = frontage * depth

Polynomial regression:

we can set that x1=size, x2=(size)^2, x3=(size)^3(remember ot feature scaling)

and it becomes linear regression

 

5. Normal Equations

Idea: method to solve for theta analytically

where  x is m*(n-1) dimensional matrix and y is a m dimensional matrix,

n : number of features, m:number of training example

And feature scaling is not necessary for normal equations

Gradient descent 

1. choose alpha

2. need many iterations

3. works well even have large number of features n.

Normal equation:
1. no need for alpha and iterations

2. need to compute matrix inverse

3. slow for large n (n = 10^6 etc)

Note  is not invertible means that:

1. you have got redundant features(linearly dependent)

2. there are too many features, delete some features, or use regularization

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/climberclimb/p/6791495.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值