|
本帖最后由 iamcodylee 于 2016-1-19 09:46 编辑
使用stanford openclassroom(Deep Learning)中的数据作为training set, exercise中使用的是Logistic Regression and Newton's method,我在训练的使用只使用了gradient descent。
- def sigmoid(inX):
- return 1.0/(1+exp(-inX))
- def gradDescent(dataMatIn, classLabels):
- x = mat(dataMatIn)
- y = mat(classLabels).transpose()
- m,n = shape(x)
- alpha = 0.001
- maxCycles = 100
- theta = ones((n,1))
- for k in range(maxCycles):
- h = sigmoid(x*theta)
- error = h - y
- theta = theta - alpha * (x.transpose() * error /m)
- return theta
复制代码 训练结果为[[ 0.97807688],[ 0.25847312],[-0.15421594]]
问题:
1、很明显这个decision boundary不对,但是我检查了半天代码,也没有发现问题到底出在哪里?
2、我理解的是,LR and Newton's method是对LR的一种改进方法,和LR比,在这里的情况下两者最终计算出来的theta应该都是很接近的吧?
补充一下:
把maxCycle修改到20W次的时候,分类器开始有效果了,但是效果好些不是太好,如图:
cost为:
Iteration 199991 | Cost: 39.786145
Iteration 199992 | Cost: 39.786110
Iteration 199993 | Cost: 39.786074
Iteration 199994 | Cost: 39.786039
Iteration 199995 | Cost: 39.786004
Iteration 199996 | Cost: 39.785968
Iteration 199997 | Cost: 39.785933
Iteration 199998 | Cost: 39.785897
Iteration 199999 | Cost: 39.785862
这样可以认为已经收敛了么?
|
|