def beg_test(): global test_data_list #数据集的文件路径由自己定义,这是我自己的路径 test_data_file = open('mnist_test.csv', 'r') test_data_list = test_data_file.readlines() test_data_file.close() all_values = test_data_list[0].split(',') print(all_values[1]) n.query((np.asfarray(all_values[1:])/255.0*0.99)+0.01) #用来存放分数,即正确率 scorecard = [] #用来存放误差平方和 mse = 0 text.insert(tk.END, '开始测试MNIST数据集.....\n') for record in test_data_list: #用','号分开数据 all_values = record.split(',') # 用准确值标签记录数字准确值 correct_label = int(all_values[0]) print('---------') print('正确结果',correct_label) # 缩放 inputs = (np.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01 # 计算输出 outputs = n.query(inputs) # 输出的最大值即为判断值 label = np.argmax(outputs) print( '神经网络判断',label) # 将正确和错误的判断形成一个列表 if (label == correct_label): # 正确为1 scorecard.append(1) else: # 错误为0 scorecard.append(0) #计算误差平方和 mse += np.sum((outputs - np.eye(10)[correct_label])**2) print(scorecard) scorecard_array = np.asarray(scorecard) #正确率 right_rate = (scorecard_array.sum() / scorecard_array.size) * 100 #总体均方误差 mse /= len(test_data_list) text.insert(tk.END, '数据测试完毕\n') text.insert(tk.END, '正确率='+str(right_rate)+'%\n') text.insert(tk.END, '总体均方误差='+str(mse)+'\n') text.update() print('正确率= ', right_rate, '%') print('总体均方误差= ', mse)

MNIST数据集测试:准确率和总体均方误差计算

原文地址: https://www.cveoy.top/t/topic/k4WV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录