Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import glob
- import os
- def printcsv(csv,names):
- for csv,name in zip(csv,names):
- print(name)
- print(csv)
- print()
- def createDict(csv,names,STD = False):
- data = {}
- for aux, name in zip(csv, names):
- array = []
- for x in range(1, 6):
- array.append(np.array(aux.iloc[:, x - 1:x]).ravel())
- data1 = {}
- data1['acuraciaMedia'] = np.mean(array[0])
- data1['precisionMedia'] = np.mean(array[1])
- data1['f1Media'] = np.mean(array[2])
- data1['recallMedia'] = np.mean(array[3])
- data1['timeMedia'] = np.mean(array[4])
- if STD:
- data1['acuraciaSTD'] = np.std(array[0])
- data1['precisionSTD'] = np.std(array[1])
- data1['f1STD'] = np.std(array[2])
- data1['recallSTD'] = np.std(array[3])
- data1['timeSTD'] = np.std(array[4])
- data[name] = data1
- return data
- def createfile(filename,pathout,outex):
- fo = open(pathout+filename+outex,'w')
- fo.write('Algorithm,Accuracy,Precision,F1,Recall,Time' + ',' + '\n')
- fo.close()
- def populatefile(data,pathout,filename,outext):
- createfile(filename,pathout,outext)
- fo = open(pathout+filename+outext,'a')
- for item in data.items():
- name = item[0]
- files = [item2[1] for item2 in item[1].items()]
- a = str("%.2f" % (files[0]*100))
- p = str("%.2f" % (files[1]*100))
- f = str("%.2f" % (files[2]*100))
- r = str("%.2f" % (files[3]*100))
- t = str("%.3f" % files[4])
- fo.write(name + ',' + a + ',' + p + ',' + f + ',' + r + ',' + t + ',' + '\n')
- fo.close()
- path = 'C:/Users/emili/Documents/Ciência da Computação/Mineração de texto/Kitchen teste/*.csv'
- pathout = 'C:/Users/emili/Documents/Ciência da Computação/Mineração de texto/'
- outext = '.csv'
- csv = [pd.read_csv(csv).iloc[:, :-1] for csv in sorted(glob.glob(path))]
- names = [os.path.basename(csv) for csv in sorted(glob.glob(path))]
- #printcsv(csv,names)
- data = createDict(csv,names,True)
- populatefile(data,pathout,'ResultadoKitchen',outext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement