Skip to content

Commit

Permalink
Update LogRegress-gj.py
Browse files Browse the repository at this point in the history
Update LogRegress-gj.py
  • Loading branch information
Jack-Cherish authored Dec 14, 2019
1 parent d836650 commit 534db64
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Logistic/LogRegres-gj.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def stocGradAscent1(dataMatrix, classLabels, numIter=150):
for i in range(m):
alpha = 4/(1.0+j+i)+0.01 #降低alpha的大小,每次减小1/(j+i)。
randIndex = int(random.uniform(0,len(dataIndex))) #随机选取样本
h = sigmoid(sum(dataMatrix[randIndex]*weights)) #选择随机选取的一个样本,计算h
error = classLabels[randIndex] - h #计算误差
weights = weights + alpha * error * dataMatrix[randIndex] #更新回归系数
h = sigmoid(sum(dataMatrix[dataIndex[randIndex]]*weights)) #选择随机选取的一个样本,计算h
error = classLabels[dataIndex[randIndex]] - h #计算误差
weights = weights + alpha * error * dataMatrix[dataIndex[randIndex]] #更新回归系数
weights_array = np.append(weights_array,weights,axis=0) #添加回归系数到数组中
del(dataIndex[randIndex]) #删除已经使用的样本
weights_array = weights_array.reshape(numIter*m,n) #改变维度
Expand Down Expand Up @@ -227,4 +227,4 @@ def plotWeights(weights_array1,weights_array2):
weights1,weights_array1 = stocGradAscent1(np.array(dataMat), labelMat)

weights2,weights_array2 = gradAscent(dataMat, labelMat)
plotWeights(weights_array1, weights_array2)
plotWeights(weights_array1, weights_array2)

0 comments on commit 534db64

Please sign in to comment.