欢迎使用CSDN-markdown编辑器

来源:互联网 发布:pe系统制作软件 编辑:程序博客网 时间:2024/06/05 14:31

Linear Regression with One Variable

trainning set

x y 1 3 2 6 3 9 4 14

Trainning examples is 4 .
x is features
y is output

Linear Algorithm

hθ=θ0+θ1x is Hypothesis.
θ=[θ0θ1]
X=11111234=[x0x1]Rm(n+1)

m=4 is the number of trainning example
n = 1 is the numbei of feature

Hypothesis:
hθ=θ0+θ1x
Parameters:
θ0,θ1
cost Function:
J(θ)=J(θ0,θ1)=12mmi=1(hθ(x(i))y(i))2=12mmi=1((θTx(i))y(i))2=12m(Xθy).2
Goal: minimizeJ(θ0,θ1)

Use Gradient descent algorithm minimize the cost function J(θ0,θ1)
repeat{
θ0:=θ0α1mmi=1(hθ(x(i))y(i))=θ0α1mmi=1((θTx(i))y(i))

θ1:=θ1α1mmi=1(hθ(x(i))y(i))x(i)=θ1α1mmi=1((θTx(i))y(i))x(i)=θ1α1m((Xθy)TX(:,2))
}
向量形式
repeat{
θ=θα1m((Xθy)TX)
}

0 0