简单的说就是每一次计算的时候计算梯度误差alpha作为更新的值

    1. for k in range(maxCycles): #heavy on matrix operations
    2. h = sigmoid(dataMatrix*weights) #matrix mult
    3. error = (labelMat - h) #vector subtraction
    4. weights = weights + alpha * dataMatrix.transpose()* error #matrix mult

    改进1
    分开每一步数据进行计算

    1. for i in range(m):
    2. h = sigmoid(sum(dataMatrix[i]*weights))
    3. error = classLabels[i] - h
    4. weights = weights + alpha * error * dataMatrix[i]

    改进2
    使用随机选择的数据进行更新,可以避免周期性的波动(每次遇到某个固定的数据波动)

    改进3
    对Alpha进行修改

    1. for j in range(numIter):
    2. dataIndex = range(m)
    3. for i in range(m):
    4. alpha = 4/(1.0+j+i)+0.0001 #apha decreases with iteration, does not
    5. randIndex = int(random.uniform(0,len(dataIndex)))#go to 0 because of the constant
    6. h = sigmoid(sum(dataMatrix[randIndex]*weights))
    7. error = classLabels[randIndex] - h
    8. weights = weights + alpha * error * dataMatrix[randIndex]
    9. del(dataIndex[randIndex])