简体   繁体   English

如何基于文本文件绘制训练和验证损失以及准确性

[英]How to plot training and validation loss and accuracy based on a text file

I am running experiments using keras on a remote server through ssh, which does not me allow to plot anything on the screen. 我正在通过ssh在远程服务器上使用keras运行实验,这不允许我在屏幕上绘制任何内容。

I have a text file which I saved the training and validation loss and accuracy. 我有一个文本文件,保存了训练和验证损失以及准确性。 I am quite newbie on plotting values from a file. 我是从文件中绘制值的新手。 How can I do that with Python? 如何使用Python做到这一点?

Ps I: The full file can be found here . 附:我:完整的文件可以在这里找到。 It looks like this 看起来像这样

epoch,acc,loss,lr,val_acc,val_loss 0,0.98254053473639,0.22349346622241112,0.001,0.9660620203871263,0.1419218496403809 1,0.991044776119403,0.06417229526104123,0.001,0.9958764657866986,0.047694865757175145 2,0.9928579098341795,0.04990571241149974,0.001,0.9843434560371118,0.08517235491136826 ... epoc,acc,loss,lr,val_acc,val_loss 0,0.98254053473639,0.22349346622241112,0.001,0.9660620203871263,0.1419218496403809 1,0.991044776119403,0.06417229526104123,0.001,0.9958764657866986,0.047694865757175145 2,0.9928579098341795,0.019900.9851 ...

Ps II: I want to plot the data in this file like in this site ps II:我想像本网站一样在该文件中绘制数据

You can use pandas for this. 您可以为此使用熊猫。 Read the description to plot the exact data configuration you need. 阅读说明以绘制所需的确切数据配置。

import pandas as pd
import matplotlib.pyplot as plt

file = pd.read_csv('test.txt')
plot = file.plot.line('loss')

plt.show()

https://pandas.pydata.org/pandas-docs/version/0.23/generated/pandas.DataFrame.plot.line.html https://pandas.pydata.org/pandas-docs/version/0.23/generated/pandas.DataFrame.plot.line.html

I solved the problem using Sharky's suggestion. 我用Sharky的建议解决了这个问题。 Here is my code: 这是我的代码:

import pandas as pd
import matplotlib.pyplot as plt

file = pd.read_csv('text_filename.txt')
lines = file.plot.line(x='epoch', y=['acc', 'val_acc'])
plt.title('CNN learning curves')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['training', 'validation'], loc='lower right')
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM