MCPcopy Index your code
hub / github.com/Dod-o/Statistical-Learning-Method_Code / model_test

Function model_test

DecisionTree/DecisionTree.py:279–295  ·  view source on GitHub ↗

测试准确率 :param testDataList:待测试数据集 :param testLabelList: 待测试标签集 :param tree: 训练集生成的树 :return: 准确率

(testDataList, testLabelList, tree)

Source from the content-addressed store, hash-verified

277 return value
278
279def model_test(testDataList, testLabelList, tree):
280 '''
281 测试准确率
282 :param testDataList:待测试数据集
283 :param testLabelList: 待测试标签集
284 :param tree: 训练集生成的树
285 :return: 准确率
286 '''
287 #错误次数计数
288 errorCnt = 0
289 #遍历测试集中每一个测试样本
290 for i in range(len(testDataList)):
291 #判断预测与标签中结果是否一致
292 if testLabelList[i] != predict(testDataList[i], tree):
293 errorCnt += 1
294 #返回准确率
295 return 1 - errorCnt / len(testDataList)
296
297if __name__ == '__main__':
298 #开始时间

Callers 1

DecisionTree.pyFile · 0.70

Calls 1

predictFunction · 0.70

Tested by

no test coverage detected