# 绘制图形以确保准确性
# 训练集准确率
plt.plot(history.history['accuracy'], label='training accuracy')
# 验证集准确率
plt.plot(history.history['val_accuracy'], label='val accuracy')
plt.title('acc')
plt.xlabel('epochs')
plt.ylabel('accuracy')
plt.savefig("./result/每一轮准确度图片.png")
plt.legend()
plt.show()
plt.plot(history.history['loss'], label='training loss')
plt.plot(history.history['val_loss'], label='val loss')
plt.title('Loss')
plt.xlabel('epochs')
plt.ylabel('loss')
plt.savefig("./result/每一轮损失值图片.png")
plt.legend()
plt.show()
input = torch.randn(3, 5, requires_grad=True)
target = torch.empty(3, dtype=torch.long).random_(5)
cross_entropy_loss = torch.nn.CrossEntropyLoss()
output = cross_entropy_loss(input, target)
loss = output
该处使用Cross-Entropy(交叉熵损失函数),参考链接https://zhuanlan.zhihu.com/p/383997503
from sklearn.metrics import accuracy_score
model = load_model('my_traffic_classifier.h5')
pred = model.predict_classes(X1_test)
print(accuracy_score(labels_test,pred))
accuracy = accuracy_score(labels_test,pred)
绘制图形
# 测试集准确率
plt.plot(accuracy, label='testing accuracy')
plt.title('acc')
plt.xlabel('epochs')
plt.ylabel('accuracy')
plt.savefig("./result/每一轮准确度图片.png")
plt.legend()
plt.show()
plt.plot(loss, label='testing loss')
plt.title('loss')
plt.xlabel('epochs')
plt.ylabel('loss')
plt.savefig("./result/每一轮损失值图片.png")
plt.legend()
plt.show()