Skip to content

Commit

Permalink
Include standard deviation info in results
Browse files Browse the repository at this point in the history
  • Loading branch information
palonso committed Mar 28, 2019
1 parent f519877 commit 49517aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def readResults(self, dir):

def best(self, n = 10, classifierType = None):
if classifierType is not None:
r = [ (cm.correct() * 100. / cm.total(), filename, param)
r = [ (cm.correct() * 100. / cm.total(), cm.stdNfold(), filename, param)
for (filename, cm, param) in self.results if param['model']['classifier'] == classifierType ]
else:
r = [ (cm.correct() * 100. / cm.total(), filename, param)
r = [ (cm.correct() * 100. / cm.total(), cm.stdNfold(), filename, param)
for (filename, cm, param) in self.results ]

print "number of results ====", len(r)
Expand Down
12 changes: 6 additions & 6 deletions src/bindings/pygaia/scripts/classification/select_best_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def selectBestModel(project_file, results_model_file, n_ranking=10):
classifierType = None # all types

cr = ClassificationResults()
print 'Loading all results...'
print('Loading all results...')
cr.readResults(results_dir)

topResults = cr.best(min(len(cr.results), n_ranking), classifierType)

accuracy, filename, params = topResults[0]
print "RESULT " + project_file + '\t' + str(accuracy) + '\t' + filename
accuracy, stdev, filename, params = topResults[0]
print('RESULT {}\tAcc:{:.3f}\tStd:{:.3f}\t{}'.format(project_file, accuracy, stdev, filename))

f.write('<h1>%s (%s)</h1>\nAccuracy: %s\n' % (className, project_file, accuracy))
f.write('<h1>%s (%s)</h1>\nAccuracy: %s. Std: %s.\n' % (className, project_file, accuracy, stdev))

cm = ConfusionMatrix()
cm.load(filename)
Expand All @@ -55,13 +55,13 @@ def selectBestModel(project_file, results_model_file, n_ranking=10):
trainSVMHistory(project_file, filename, results_model_file, className)
shutil.copyfile(filename, results_model_file + '.param')

topResultsDict = {idx: {'accuracy': entry[0], 'config': entry[2],
topResultsDict = {idx: {'accuracy': entry[0], 'std': entry[1], 'config': entry[3],
'results_file': entry[1]} for idx, entry in enumerate(topResults)}
yaml.dump(topResultsDict, open(
results_model_file + '.results.ranking', 'w'))

else:
print "RESULT " + "No results found for ", project_file, ": cannot build a model"
print("RESULT " + "No results found for ", project_file, ": cannot build a model")
f.write('<h1>%s (%s) </h1>\nResults not found\n' % (collection, project_file))


Expand Down

0 comments on commit 49517aa

Please sign in to comment.