逻辑回归(Logistic Regression)

1.推导

逻辑回归(Logistic Regression)      sigmoid函数

逻辑回归(Logistic Regression)

逻辑回归(Logistic Regression)

2式可以简化为 逻辑回归(Logistic Regression)

逻辑回归(Logistic Regression)

逻辑回归(Logistic Regression)

使用梯度下降法求J(θ)的最小值,θ的更新过程:

逻辑回归(Logistic Regression)

逻辑回归(Logistic Regression)

逻辑回归(Logistic Regression)

逻辑回归(Logistic Regression)

逻辑回归(Logistic Regression)

    for k in range(maxCycles):              #heavy on matrix operations

        h = sigmoid(dataMatrix*weights)  

        error = (labelMat - h)              #vector subtraction

        weights = weights + alpha * dataMatrix.transpose()* error

    return weights

3.改进

逻辑回归(Logistic Regression)

    for j in range(numIter):

        dataIndex = range(m)

        for i in range(m):

            alpha = 4/(1.0+j+i)+0.0001    #apha decreases with iteration, does not

            randIndex = int(random.uniform(0,len(dataIndex)))#go to 0 because of the constant

            h = sigmoid(sum(dataMatrix[randIndex]*weights))

            error = classLabels[randIndex] - h

            weights = weights + alpha * error * mat(dataMatrix[randIndex]).transpose()

            del(dataIndex[randIndex])//?不放回

 

http://blog.jobbole.com/113182/

https://www.cnblogs.com/alfred2017/p/6627824.html