Esempio n. 1
0
def print_accuracy(total, predicted, true_pred, false_pred):
    print("""
        Predicted: {0} out of {1} correct! ({2}%)
        Predicted: {3} out of {4} peaks correct! ({5}%)
        Predicted: {6} out of {7} nopeaks correct! ({8}%)
        Total accuracy: {9}%""".format(
        sum(true_pred.values()), sum(total.values()), 100*(sum(true_pred.values())/float(sum(total.values()))),
        true_pred['peak'], total['peak'], 100*(true_pred['peak']/float(total['peak'])),
        true_pred['nopeak'], total['nopeak'], 100*(true_pred['nopeak']/float(total['nopeak'])),
        100*(sum(true_pred.values())/float(sum(total.values())))
        ))

if __name__ == '__main__':
    start_time = time.time()
    dataset    = gs2.load_json('all_data.json')
    train,test = split_dataset(dataset, 0.67)
    # TODO: Resort and resummarize so we know which files are training and which files are testing
    if 'resort' in sys.argv:
        sort_data(train)
    if 'resummarize' in sys.argv:
        summarize_by_class()

    summaries = database.get_summaries()
    if 'test' in sys.argv:
        t_predictions = {'total':{'peak':0, 'nopeak':0},'predicted':{'peak':0, 'nopeak':0},'true_pred':{'peak':0, 'nopeak':0},'false_pred':{'peak':0, 'nopeak':0}}
        for ts in test:
            print("Testing "+ts.name+"...")
            f_predictions = {'total':{'peak':0, 'nopeak':0},'predicted':{'peak':0, 'nopeak':0},'true_pred':{'peak':0, 'nopeak':0},'false_pred':{'peak':0, 'nopeak':0}}
            file_time_start = time.time()
            for s in ts.sections:
Esempio n. 2
0
#!/usr/bin/env python3
import os
import time
import gs2

startTime = time.time()

FILE_LOCATION = "./GS2-filer/"  # Put gs2 files here
JSON_FILE = "all_data.json"
gs2s = []
try:
    gs2.load_json(JSON_FILE, gs2s)
except FileNotFoundError as ex:
    print(ex.strerror + ": ", ex.filename)
    if ex.filename == JSON_FILE:
        try:
            all_files = [f for f in os.listdir(FILE_LOCATION) if
                         os.path.isfile(os.path.join(FILE_LOCATION, f))]  # gets all files in folder

            files = [f for f in all_files if
                     f.lower().endswith(".gs2")]  # gets files that starts with uke
            for f in files:
                print("Processing", FILE_LOCATION + f + "...")
                data_object = gs2.GS2File()
                file = data_object.process_file(FILE_LOCATION + f)
                gs2s.append(data_object)
                print(FILE_LOCATION + f, "processed...")
            print("Saving to json:", JSON_FILE)
            gs2.save_json(gs2s, JSON_FILE)
            print("Saved to json file:", JSON_FILE)
        except FileNotFoundError as ex2: