def testSVM(clf, dataSet):
labels, instances = dataSet.getLabelsAndInstances()
predictionsLoL = map(clf.predict, instances)
numWrong = 0
numPred = 0
for i in range(len(labels)):
l = labels[i]
predList = predictionsLoL[i]
wrongList = it.ifilter(lambda x: x!=l, predList)
numWrong += len(wrongList)
numPred += len(predList)
print "Wrong: ", numWrong
print "Predicted: ", numPred
print "Percent: ", float(numWrong)/numPred
评论列表
文章目录