defcolicTest():
frTrain =open('horseColicTraining.txt')
frTest =open('horseColicTest.txt')
trainingSet =[]
trainingLabels =[]for line in frTrain.readlines():
currLine = line.strip().split('\t')
lineArr =[]for i inrange(21):
lineArr.append(float(currLine[i]))
trainingSet.append(lineArr)
trainingLabels.append(float(currLine[21]))
trainWeights = stocGradAscent1(array(trainingSet),trainingLabels,500)
errorCount =0;
numTestVec =0.0for line in frTest.readlines():
numTestVec +=1.0
currLine = line.strip().split('\t')
lineArr=[]for i inrange(21):
lineArr.append(float(currLine[i]))ifint(classifyVector(array(lineArr),trainWeights))!=int(currLine[21]):
errorCount +=1
errorRate =(float(errorCount)/numTestVec)print("the error rate of this test is:%f"% errorRate)return errorRate
defmultiTest():
numTests =10
errorSum =0.0for k inrange(numTests):
errorSum += colicTest()print("after %d itertaions the average error rate is : %f"%(numTests,errorSum/float(numTests)))
multiTest()
E:\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: RuntimeWarning: overflow encountered in exp
the error rate of this test is:0.343284
the error rate of this test is:0.328358
the error rate of this test is:0.358209
the error rate of this test is:0.373134
the error rate of this test is:0.447761
the error rate of this test is:0.253731
the error rate of this test is:0.268657
the error rate of this test is:0.253731