def main(_): y_eval, logits_list = eval() # analyse result: each_result = len(logits_list) / 4 i = 0 true_positive = 0 true_negative = 0 false_positive = 0 false_negative = 0 for rst in logits_list: lab = 0 rst = rst.tolist() rst = rst.index(max(rst)) if i < each_result: lab = 0 elif i < each_result * 2: lab = 1 elif i < each_result * 3: lab = 2 else: lab = 3 if lab == 3 and rst == 3: true_positive += 1 elif lab != 3 and rst == 3: false_positive += 1 elif lab == 3 and rst != 3: true_negative += 1 i += 1 with open("result", "a") as outfile: outfile.write("NN Result:\n") outfile.write("total number:" + str(len(logits_list)) + "\n") outfile.write("true_positive:" + str(true_positive) + "(" + str(round(true_positive / len(logits_list) * 100, 2)) + "%)\n") outfile.write("false_positive:" + str(false_positive) + "(" + str(round(false_positive / len(logits_list) * 100, 2)) + "%)\n") outfile.write("true_negative:" + str(true_negative) + "(" + str(round(true_negative / len(logits_list) * 100, 2)) + "%)\n") outfile.close() print("NN result:") print("total number:" + str(len(logits_list))) print("true_positive:" + str(true_positive)) print("false_positive:" + str(false_positive)) print("true_negative:" + str(true_negative)) # ensemble with SVM SVM_pred_list = SVM.SVM_eval() ratio_neural, ratio_SVM, ensemble_pred_list = change_ensemble_weight( logits_list, SVM_pred_list, y_eval) with open("runs/ratio", "w") as outfile: outfile.write(str(ratio_neural)) outfile.write(" ") outfile.write(str(ratio_SVM)) outfile.close() # enhance result by keywords layer_list, weight_list, word_num_test, headlines_test, labels_test, keywords_list = Keywords_analysis.analyze_low_to_high( ) prediction_list = create_keyword_prediction(layer_list, weight_list, word_num_test, headlines_test, labels_test, keywords_list) for neural_pred, keywords_pred, label, headlines in zip( ensemble_pred_list, prediction_list, y_eval, headlines_test): keyword_num = 0 First3_num = 0 word_num = 0 i = 1 for word in headlines: if word in keywords_list: keyword_num += 1 if i <= 3: First3_num += 1 word_num += 1 i += 1 weight_list = change_keyword_weight(weight_list, keywords_pred, neural_pred, word_num, keyword_num, First3_num, label) np_weight_list = np.array(weight_list) np.save("runs/weight_list", np_weight_list) np.save("runs/keywords_layers", layer_list) weight_list = np.load("runs/weight_list.npy") final_pred(ensemble_pred_list, prediction_list, weight_list, y_eval, headlines_test, keywords_list)
def main(_): y_eval, logits_list = eval() # analyse result: each_result = len(logits_list) / 4 i = 0 true_positive = 0 true_negative = 0 false_positive = 0 false_negative = 0 for rst in logits_list: lab = 0 rst = rst.tolist() rst = rst.index(max(rst)) if i < each_result: lab = 0 elif i < each_result * 2: lab = 1 elif i < each_result * 3: lab = 2 else: lab = 3 if lab == 3 and rst == 3: true_positive += 1 elif lab != 3 and rst == 3: false_positive += 1 elif lab == 3 and rst != 3: true_negative += 1 i += 1 with open("result", "a") as outfile: outfile.write("NN Result:\n") outfile.write("total number:" + str(len(logits_list)) + "\n") outfile.write("true_positive:" + str(true_positive) + "(" + str(round(true_positive / len(logits_list) * 100, 2)) + "%)\n") outfile.write("false_positive:" + str(false_positive) + "(" + str(round(false_positive / len(logits_list) * 100, 2)) + "%)\n") outfile.write("true_negative:" + str(true_negative) + "(" + str(round(true_negative / len(logits_list) * 100, 2)) + "%)\n") outfile.close() print("NN result:") print("total number:" + str(len(logits_list))) print("true_positive:" + str(true_positive)) print("false_positive:" + str(false_positive)) print("true_negative:" + str(true_negative)) # ensemble with SVM SVM_pred_list = SVM.SVM_eval() ratio_neural, ratio_SVM, ensemble_pred_list = change_ensemble_weight( logits_list, SVM_pred_list, y_eval) with open("runs/ratio", "w") as outfile: outfile.write(str(ratio_neural)) outfile.write(" ") outfile.write(str(ratio_SVM)) outfile.close()