Ejemplo n.º 1
0
    threshold = 0.25
    precision, recall, tn, fn, tp, fp = my_metrics.precision_and_recall(true_Y_array, score_predicted_Y_array, threshold = threshold)
    print("For Threshold = " + str(threshold) + ": TN: " + str(tn) + " FN: " + str(fn) + " TP: " + str(tp) + " FP: " + str(fp))
    print("    Precision = " + str("{0:.3f}".format(precision)))
    print("    Recall = " + str("{0:.3f}".format(recall)))


my_metrics.plot_PR(true_Y_array, score_predicted_Y_array)
my_metrics.plot_ROC(true_Y_array, score_predicted_Y_array)





my_metrics.plot_multiple_ROC(true_Y_array, score_predicted_Y_array,true_Y_array, score_predicted_Y_array_2)
my_metrics.plot_multiple_PR(true_Y_array, score_predicted_Y_array,true_Y_array, score_predicted_Y_array_2)

#the following code can be moved into the "for loop" for additional / different output:

	###########################################
	############# Training Test ###############
	###########################################
	#true_Y_array = my_utils.matrix_from_list(trainY).flatten()
	#score_predicted_Y_array = predict(sparse_trainX[0:10000].todense()).flatten()
	#print("TRAINSET:")
	#roc_auc, pr_auc = my_metrics.ROCAUC_and_PRAUC(true_Y_array, score_predicted_Y_array)
	#print("ROC-AUC = " + str("{0:.3f}".format(roc_auc)))
	#print("PR-AUC = " + str("{0:.3f}".format(pr_auc)))

	#threshold = 0.25
Ejemplo n.º 2
0
print("   F1 = " + str("{0:.3f}".format(f1)))



sparse_trainX, trainY, sparse_testX, testY = my_load.load(make_X_sparse = True, paths=["/home/stud/gales/twnn/S/trX395", "/home/stud/gales/twnn/S/trY395", "/home/stud/gales/twnn/S/teX395", "/home/stud/gales/twnn/S/teY395"])

clf = MultinomialNB()
clf.fit(sparse_trainX, trainY)

second_score = clf.predict_proba(sparse_testX).flatten()
second_true = my_utils.matrix_from_list(testY).flatten()

threshold = 0.4
precision, recall, tn, fn, tp, fp = my_metrics.precision_and_recall(second_true, second_score, threshold = threshold)
print(" For Threshold = " + str(threshold) + ": TN: " + str(tn) + " FN: " + str(fn) + " TP: " + str(tp) + " FP: " + str(fp))
print("    Precision = " + str("{0:.3f}".format(precision)))
print("    Recall = " + str("{0:.3f}".format(recall)))


threshold, precision, recall, f1 = my_metrics.find_best_threshold_for_precision_recall(second_true, second_score)
print(" For Threshold = " + str(threshold) + ":")
print("   Precision = " + str("{0:.3f}".format(precision)))
print("   Recall = " + str("{0:.3f}".format(recall)))
print("   F1 = " + str("{0:.3f}".format(f1)))

my_metrics.plot_multiple_PR(true_Y_array, score_predicted_Y_array, second_true, second_score)
my_metrics.plot_multiple_ROC(true_Y_array, score_predicted_Y_array, second_true, second_score)