From 5117f8276628909e02b463ed6719c5f3ac787e6a Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Wed, 24 Apr 2024 12:26:38 -0500 Subject: [PATCH] snapshot... --- modules/machine_learning/classification.py | 25 +++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/machine_learning/classification.py b/modules/machine_learning/classification.py index 8607a124..035ef544 100644 --- a/modules/machine_learning/classification.py +++ b/modules/machine_learning/classification.py @@ -60,12 +60,12 @@ def logistic_regression(x, y): yhat_prob = LR.predict_proba(x_test) print(confusion_matrix(y_test, yhat, labels=[1,0])) - print('Accuracy: ', accuracy_score(y_test, yhat)) - print('Jaccard Idx: ', jaccard_score(y_test, yhat)) - print('Precision: ', precision_score(y_test, yhat)) - print('Recall: ', recall_score(y_test, yhat)) - print('F1: ', f1_score(y_test, yhat)) - print('AUC: ', roc_auc_score(y_test, yhat_prob[:, 1])) + print('Accuracy: ', "{:.4f}".format(accuracy_score(y_test, yhat))) + print('Jaccard Idx: ', "{:.4f}".format(jaccard_score(y_test, yhat))) + print('Precision: ', "{:.4f}".format(precision_score(y_test, yhat))) + print('Recall: ', "{:.4f}".format(recall_score(y_test, yhat))) + print('F1: ', "{:.4f}".format(f1_score(y_test, yhat))) + print('AUC: ', "{:.4f}".format(roc_auc_score(y_test, yhat_prob[:, 1]))) def k_nearest_neighbors(x, y, k=4): @@ -82,10 +82,9 @@ def k_nearest_neighbors(x, y, k=4): yhat = KN_C.predict(x_test) yhat_prob = KN_C.predict_proba(x_test) - print(confusion_matrix(y_test, yhat, labels=[1,0])) - print('Accuracy: ', accuracy_score(y_test, yhat)) - print('Jaccard Idx: ', jaccard_score(y_test, yhat)) - print('Precision: ', precision_score(y_test, yhat)) - print('Recall: ', recall_score(y_test, yhat)) - print('F1: ', f1_score(y_test, yhat)) - print('AUC: ', roc_auc_score(y_test, yhat_prob[:, 1])) \ No newline at end of file + print('Accuracy: ', "{:.4f}".format(accuracy_score(y_test, yhat))) + print('Jaccard Idx: ', "{:.4f}".format(jaccard_score(y_test, yhat))) + print('Precision: ', "{:.4f}".format(precision_score(y_test, yhat))) + print('Recall: ', "{:.4f}".format(recall_score(y_test, yhat))) + print('F1: ', "{:.4f}".format(f1_score(y_test, yhat))) + print('AUC: ', "{:.4f}".format(roc_auc_score(y_test, yhat_prob[:, 1]))) \ No newline at end of file -- GitLab