diff --git a/modules/machine_learning/classification.py b/modules/machine_learning/classification.py index 8607a124b7038d4c0a6108800dadb3bb156ac8ac..035ef544625b7c364f2f72b4c2176ea7b58b4da5 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