Advertisement
11eimilia11

i just wan to mimi

Dec 2nd, 2019
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import glob
  4. import os
  5.  
  6. def printcsv(csv,names):
  7. for csv,name in zip(csv,names):
  8. print(name)
  9. print(csv)
  10. print()
  11.  
  12. def createDict(csv,names,STD = False):
  13. data = {}
  14.  
  15. for aux, name in zip(csv, names):
  16. array = []
  17. for x in range(1, 6):
  18. array.append(np.array(aux.iloc[:, x - 1:x]).ravel())
  19.  
  20. data1 = {}
  21. data1['acuraciaMedia'] = np.mean(array[0])
  22. data1['precisionMedia'] = np.mean(array[1])
  23. data1['f1Media'] = np.mean(array[2])
  24. data1['recallMedia'] = np.mean(array[3])
  25. data1['timeMedia'] = np.mean(array[4])
  26.  
  27. if STD:
  28. data1['acuraciaSTD'] = np.std(array[0])
  29. data1['precisionSTD'] = np.std(array[1])
  30. data1['f1STD'] = np.std(array[2])
  31. data1['recallSTD'] = np.std(array[3])
  32. data1['timeSTD'] = np.std(array[4])
  33.  
  34. data[name] = data1
  35.  
  36. return data
  37.  
  38. def createfile(filename,pathout,outex):
  39.  
  40. fo = open(pathout+filename+outex,'w')
  41. fo.write('Algorithm,Accuracy,Precision,F1,Recall,Time' + ',' + '\n')
  42. fo.close()
  43.  
  44. def populatefile(data,pathout,filename,outext):
  45.  
  46. createfile(filename,pathout,outext)
  47.  
  48. fo = open(pathout+filename+outext,'a')
  49.  
  50. for item in data.items():
  51. name = item[0]
  52. files = [item2[1] for item2 in item[1].items()]
  53.  
  54. a = str("%.2f" % (files[0]*100))
  55. p = str("%.2f" % (files[1]*100))
  56. f = str("%.2f" % (files[2]*100))
  57. r = str("%.2f" % (files[3]*100))
  58. t = str("%.3f" % files[4])
  59.  
  60. fo.write(name + ',' + a + ',' + p + ',' + f + ',' + r + ',' + t + ',' + '\n')
  61.  
  62. fo.close()
  63.  
  64. path = 'C:/Users/emili/Documents/Ciência da Computação/Mineração de texto/Kitchen teste/*.csv'
  65. pathout = 'C:/Users/emili/Documents/Ciência da Computação/Mineração de texto/'
  66. outext = '.csv'
  67.  
  68. csv = [pd.read_csv(csv).iloc[:, :-1] for csv in sorted(glob.glob(path))]
  69. names = [os.path.basename(csv) for csv in sorted(glob.glob(path))]
  70.  
  71. #printcsv(csv,names)
  72.  
  73.  
  74. data = createDict(csv,names,True)
  75. populatefile(data,pathout,'ResultadoKitchen',outext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement