Skip to content
Permalink
f9ee841a5c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
39 lines (34 sloc) 1.45 KB
import constants as cst
import subprocess as sp
import re
import os
def run_random_forest1(base_dir_name, experiment_name):
file_path = cst.BASE + base_dir_name + "/" + experiment_name + "/out.arff"
if not os.path.exists(file_path):
return None
try:
output = str(sp.check_output(["java", "-cp", cst.WEKA_BIN,
"weka.classifiers.trees.RandomForest", '-P', '100', '-I',
'100', '-num-slots', '1', '-K', '0', '-M', '1.0', '-V', '0.001', '-S', '1',
"-t", file_path], timeout=30))
match = re.search('Correctly Classified Instances\s+\d+\s+(\d+\.\d+)\s+%', output)
if match:
return experiment_name + "," + match.group(1)
return experiment_name + ",?"
except sp.TimeoutExpired:
print("timeout exceeded", experiment_name)
return experiment_name + ",?"
def classify_experiments(base_dir_name):
results = []
for experiment in os.listdir(cst.BASE + base_dir_name):
if 'cubes' not in experiment:
continue
classification = run_random_forest1(base_dir_name, experiment)
results.append(classification)
results.append("\n")
return results
if __name__ == '__main__':
base_dir_name = "logs_test"
res = classify_experiments(base_dir_name)
with open(cst.BASE + base_dir_name + "/Classification.csv", "w") as f:
f.writelines(res)