您的位置:首页 > 编程语言

每天30行代码——随机梯度上升算法

2017-11-26 22:27 274 查看
  梯度上升算法每次更新回归系数时都要遍历整个数据集,在样本数较少时还可以,当样本数目太多时复杂度太高,所以产生了随机梯度上升算法,每次仅用一个样本点来更新回归系数。

  

def stocGradAscent0(dataMatrix,classLabels):
m,n=shape(dataMatrix)
alpha=0.01
weights=ones(n)
for i in range(m):
h=sigmoid(sum(dataMatrix[i]*weights))
error=classLabels[i]-h
weights=weights+alpha*error*dataMatrix[i]
return weights
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: