def genROCFile(name, data, threshold=0.05): resultRow = [] resultRow.append(name) resultRow.append(threshold) true_alerts = 0.0 false_alerts = 0.0 total_alert = 0.0 pos = 0.0 neg = 0.0 found = [] for i, file_name in enumerate(data.get_files_test()): ut.checkFolderandCreate("{}\\Changepoint\\{}".format(main_path, algo_name)) pickle_file = '{}\\Changepoint\\{}\\_{}_threshold{}_index_{:03d}.pkl'.format \ (main_path, algo_name, name, threshold, i) instances = data.get_dataset_test(i) if not os.path.exists(pickle_file): change_points,max_num, max_bin = dybin(instances=instances, threshold=threshold) ut.checkFolderandCreate("{}\\listbin".format(main_path)) ut.checkFolderandCreate("{}\\listbin\\{}".format(main_path, algo_name)) txt_file = '{}\\listbin\\{}\\_{}_threshold{}_index_{:03d}.txt'.format \ (main_path, algo_name, name, threshold, i) ut_light.export_list_bin_txt(max_num=max_num,max_bin=max_bin,txt_file=txt_file) with open(pickle_file, 'wb') as output: pickle.dump(change_points, output) else: with open(pickle_file, 'rb') as pickle_input: change_points = pickle.load(pickle_input) start_end = data.get_dataset_answer_st_ed(index=i)[0] row = ut_light.calRowTF_NoBin(start=start_end[0], end=start_end[1], change_points=change_points, size_instances=len(instances), bin_size=bin_size) true_alerts = true_alerts + row[0] false_alerts = false_alerts + row[1] total_alert = total_alert + row[2] pos = pos + row[3] neg = neg + row[4] found.append(row[9]) resultRow = [] resultRow.append(name) resultRow.append(threshold) resultRow.append(true_alerts) resultRow.append(false_alerts) resultRow.append(total_alert) resultRow.append(pos) resultRow.append(neg) tp_rate = float(true_alerts) / pos resultRow.append(tp_rate) fp_rate = float(false_alerts) / neg resultRow.append(fp_rate) resultRow.append(sum(found)) return resultRow
def genROCFile(name, data, threshold=0.05): resultRow = [] resultRow.append(name) resultRow.append(threshold) true_alerts = 0.0 false_alerts = 0.0 total_alert = 0.0 pos = 0.0 neg = 0.0 found = [] for i, file_name in enumerate(data.get_files_test()): instances = data.get_dataset_test(i) start_end = data.get_dataset_answer_st_ed(index=i)[0] change_points_list = [] for bin_size in bin_sizes: algo_name = "skbin_{}".format(bin_size) pickle_file = '{}\\Changepoint\\{}\\_{}_threshold{}_index_{:03d}.pkl'.format \ (main_path, algo_name, name, threshold, i) if os.path.exists(pickle_file): with open(pickle_file, 'rb') as pickle_input: change_points = pickle.load(pickle_input) change_points = ut_light.gen_change_points_list( change_points=change_points, bin_size=bin_size) change_points_list.append(change_points) SEA_change_points = union_block(change_points_list=change_points_list) row = ut_light.calRowTF_NoBin(start=start_end[0], end=start_end[1], change_points=SEA_change_points, size_instances=len(instances), bin_size=1) true_alerts = true_alerts + row[0] false_alerts = false_alerts + row[1] total_alert = total_alert + row[2] pos = pos + row[3] neg = neg + row[4] found.append(row[9]) resultRow = [] resultRow.append(name) resultRow.append(threshold) resultRow.append(true_alerts) resultRow.append(false_alerts) resultRow.append(total_alert) resultRow.append(pos) resultRow.append(neg) tp_rate = float(true_alerts) / pos resultRow.append(tp_rate) fp_rate = float(false_alerts) / neg resultRow.append(fp_rate) resultRow.append(sum(found)) return resultRow