PageRenderTime 67ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/python_data_analysis/affective_confusion_matrix.py

https://bitbucket.org/diogo149/affective-computing
Python | 33 lines | 28 code | 5 blank | 0 comment | 3 complexity | f215b0ddf7b7fae881255dde2b7cb46b MD5 | raw file
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4. def get_filename(game, window):
  5. assert game in games
  6. assert window in windows
  7. return "../new_data/error_%s_%d.csv" % (game, window)
  8. def confusion_matrix(df, name):
  9. arr = df.as_matrix()
  10. fig = plt.figure()
  11. plt.clf()
  12. ax = fig.add_subplot(111)
  13. ax.set_aspect(1)
  14. res = ax.imshow(np.array(arr), cmap=plt.cm.jet, interpolation='nearest')
  15. cb = fig.colorbar(res)
  16. plt.xticks(range(df.shape[1]), df.columns, rotation='vertical')
  17. plt.yticks(range(df.shape[0]), df.index)
  18. plt.savefig(name + '.png', format='png')
  19. plt.close()
  20. if __name__ == "__main__":
  21. games = ["sahara", "escape"]
  22. windows = [2, 1]
  23. name = "../new_data/error_sahara_1.csv"
  24. for game in games:
  25. for window in windows:
  26. name = get_filename(game, window)
  27. print name
  28. confusion_matrix(pd.read_csv(name, index_col=0), name)