Skip to content

Commit 7aec90d

Browse files
committed
add digitRecognition function
1 parent 74152ab commit 7aec90d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

logistic regression/use Python and NumPy/logistic regression.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def sigmoid(inX):
5050
return 1.0/(1+exp(-inX))
5151

5252
#alpha:步长,maxCycles:迭代次数,可以调整
53-
def gradAscent(dataArray,labelArray,alpha=0.05,maxCycles=7):
53+
def gradAscent(dataArray,labelArray,alpha,maxCycles):
5454
dataMat=mat(dataArray) #size:m*n
5555
labelMat=mat(labelArray) #size:m*1
5656
m,n=shape(dataMat)
@@ -73,13 +73,18 @@ def classfy(testdir,weigh):
7373
print int(labelMat[i]),'is classfied as: 1'
7474
if int(labelMat[i])!=1:
7575
error+=1
76+
print 'error'
7677
else:
7778
print int(labelMat[i]),'is classfied as: 0'
7879
if int(labelMat[i])!=0:
7980
error+=1
81+
print 'error'
8082
print 'error rate is:','%.4f' %(error/m)
8183

82-
84+
def digitRecognition(trainDir,testDir,alpha=0.07,maxCycles=10):
85+
data,label=loadData(trainDir)
86+
weigh=gradAscent(data,label,alpha,maxCycles)
87+
classfy(testDir,weigh)
8388

8489

8590

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@author: wepon
2+
@github: https://github.com/wepe
3+
4+
Detailed discussion for this project,visit my blog: http://blog.csdn.net/u012162613
5+

0 commit comments

Comments
 (0)