MCPcopy
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / colicTest

Function colicTest

Logistic regression/Logistic.py:81–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79 else: return 0.0
80
81def colicTest():
82 frTrain = open('horseColicTraining.txt')
83 frTest = open('horseColicTest.txt')
84 trainingSet = []; trainingLabels = []
85 for line in frTrain.readlines():
86 currLine = line.strip().split('\t')
87 lineArr = []
88 for i in range(21):
89 lineArr.append(float(currLine[i]))
90 trainingSet.append(lineArr)
91 trainingLabels.append(float(currLine[21]))
92 trainWeights = stocGradAscent1(array(trainingSet), trainingLabels, 500)
93 errorCount = 0; numTestVec = 0.0
94 for line in frTest.readlines():
95 numTestVec += 1.0
96 currLine = line.strip().split('\t')
97 lineArr = []
98 for i in range(21):
99 lineArr.append(float(currLine[i]))
100 if int(classifyVector(array(lineArr), trainWeights)) != int(currLine[21]):
101 errorCount += 1
102 errorRate = float(errorCount)/numTestVec
103 print("the error rate of this test is: %f" % errorRate)
104 return errorRate
105
106def multiTest():
107 numTests = 10; errorSum = 0.0

Callers 1

multiTestFunction · 0.85

Calls 3

stocGradAscent1Function · 0.85
classifyVectorFunction · 0.85
splitMethod · 0.80

Tested by

no test coverage detected