-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsaveFile2.py
More file actions
33 lines (27 loc) · 1.06 KB
/
Copy pathsaveFile2.py
File metadata and controls
33 lines (27 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pickle
def saveResults(fileName,*args,**kwargs):
f=open(fileName,'w')
for i in args:
f.writelines(str(i)+'\n')
f.close()
return
def saveLog(fileName,log):
f=open(fileName,'wb')
pickle.dump(log,f)
f.close()
return
def bestInd(toolbox,population,number):
bestInd=[]
best=toolbox.selectElitism(population, k=number)
for i in best:
bestInd.append(i)
return bestInd
def saveAllResults(randomSeeds,dataSetName,best_ind_va,log,hof,num_features,trainTime,testTime,testResults):
fileName1= str(randomSeeds)+'Resultson' + dataSetName+ '.txt'
saveLog(fileName1, log)
fileName2=str(randomSeeds)+'FinalResultson' + dataSetName+ '.txt'
saveResults(fileName2, 'randomSeed', randomSeeds, 'trainTime', trainTime,
'trainResults', best_ind_va.fitness, 'Number of features', num_features,
'testTime', testTime, 'testResults', testResults, 'bestInd in training',
best_ind_va, 'Best individual in each run',*hof[:])
return