-1

I am running experiments using keras on a remote server through ssh, which does not me allow to plot anything on the screen.

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?

P.s 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 ...

P.s II: I want to plot the data in this file like in this site

Sharky
  • 4,473
  • 2
  • 19
  • 27
mad
  • 2,677
  • 8
  • 35
  • 78
  • 1
    Where do you want to plot them? What is the expected output. Add some context please. And what does it have to do with Keras? – Sharky Mar 31 '19 at 14:11
  • @Sharky it was generated by the keras training. I want to plot the data in this file like in this site https://machinelearningmastery.com/display-deep-learning-model-training-history-in-keras/. However, the data I have is stored in a text file. Thanks. – mad Mar 31 '19 at 14:49
  • 1
    Please avoid posting walls of text with your data. Your question has likely been already answered on SO, e.g. [here](https://stackoverflow.com/questions/11248812/how-to-plot-data-from-multiple-two-column-text-files-with-legends-in-matplotlib) – Daniele Grattarola Mar 31 '19 at 15:02

2 Answers2

2

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

Sharky
  • 4,473
  • 2
  • 19
  • 27
2

I solved the problem using Sharky's suggestion. 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()
mad
  • 2,677
  • 8
  • 35
  • 78