def one_point_hybridization_knn_result(forest_old, feature_list, trainx, trainy, predictx, predicty,loop,neighbor): res = {} for i in range(0, loop): forest, forest_new = one_point_hybridization_knn(forest_old, feature_list, trainx, trainy, predictx, predicty,neighbor) forest_list = sorted(forest.items(), key=lambda item:(item[1],item[0]), reverse=True) forest_next = [] for j in range(0, 10): forest_next.append(forest_old[j]) for j in range(0, 30): forest_next.append(num_to_list(forest_list[j][0])) gene_mutation_list = [] for j in range(30, 40): gene_mutation_list.append(num_to_list(forest_list[j][0])) positive_table, nagative_table = calculate_table_knn(gene_mutation_list, feature_list, trainx, trainy, predictx, predicty,neighbor) for j in range(0, 10): forest_next.append(gene_mutation(positive_table, nagative_table)) forest_old = forest_next # res.append(forest_list[0][1]) res[forest_list[0][0]]=forest_list[0][1] first=sorted(res.items(), key=lambda item:(item[1],item[0]),reverse=True)[0] return first
def one_point_hybridization_train_tree_high_result(forest_old, feature_list, trainx, trainy, predictx, predicty, loop): res = {} for i in range(0, loop): forest, forest_new = one_point_hybridization_train_tree( forest_old, feature_list, trainx, trainy, predictx, predicty) forest_list = sorted(forest.items(), key=lambda item: (item[1], item[0]), reverse=True) forest_next = [] for j in range(0, 10): forest_next.append(forest_old[j]) for j in range(0, 40): forest_next.append(num_to_list(forest_list[j][0])) forest_old = forest_next # res.append(forest_list[0][1]) res[forest_list[0][0]] = forest_list[0][1] first = sorted(res.items(), key=lambda item: (item[1], item[0]), reverse=True)[0] return first
# print 'predict_sample',predict_sample # print 'predict_y',predicty acc = train_knn(train_sample, trainy, predict_sample, predicty, 1) num_string = num_to_string(num) forest[num_string] = acc # forest_area = [] forest_old = init_forest res = {} for i in range(0, 5): forest, forest_new = one_point_hybridization_knn( forest_old, feature_list, trainx, trainy, predictx, predicty, 1) forest_list = sorted(forest.items(), key=lambda item: item[1], reverse=True) forest_next = [] for j in range(0, 10): forest_next.append(forest_old[j]) for j in range(0, 40): forest_next.append(num_to_list(forest_list[j][0])) forest_old = forest_next res[forest_list[0][0]] = forest_list[0][1] # for j in forest_list: # print j # forest_area.append(string_to_numlist(forest_list[0][0])) ans = sorted(res.items(), key=lambda item: item[1], reverse=True) for i in ans: print 'accuracy=', i[1], 'DR=', calculate_DR(i[0])