1 2 3 4 5 6 7 8 9 10 11 12 13
| myDataSet, myCategory = file2DataSet("E:/dataSet/tree/lenses.data") myDataSetForTrain, myDataSetForTest = split(myDataSet, (math.ceil(len(myDataSet) * 0.7),)) myCategoryForTrain, myCategoryForTest = split(myCategory, (math.ceil(len(myCategory) * 0.7),)) p1Vec, p2Vec, p3Vec, pClass1, pClass2, pClass3 = trainNBO(myDataSetForTrain, myCategoryForTrain) myDataSetForTest = prepareDataSetForTest(myDataSetForTest) errorCount = 0 numForTest = len(myDataSetForTest) for x in range(numForTest): result = classifyNB(myDataSetForTest[x], p1Vec, p2Vec, p3Vec, pClass1, pClass2, pClass3) print("the classifier came back, with: %d, the real answer is: %d" % (result, myCategoryForTest[x])) if (result != myCategoryForTest[x]): errorCount += 1.0 print("the total error rate is: %f" % (errorCount / float(numForTest)))
|