Commit 8cab8361 by markus

### Added simple metrics for comparison

parent 6dd39cf0
lib/ml_metrics.py 0 → 100644
 def accuracy(TP : int, TN : int, FP : int, FN : int) -> float: """Ratio of correct predicitons to all predictions. :param TP: True positives :param TN: True negatives :param FP: False positives :param FN: False negatives """ return (TP + TN) / (TP + TN + FP + FN) def precision(TP : int, FP : int) -> float: """Number of true positives in all positives. :param TP: True positives :param FP: False negatives """ return TP / (TP + FP) def recall(TP : int, FN : int) -> float: """How many true instances were calssified correctly? :param TP: True positives :param FN: False negatives """ return TP / (TP + FN) def f1_score(TP : int, FP : int, FN : int) -> float: """Weighted average between precision and recall. :param TP: True positives :param FP: False positives :param FN: False negatives """ return 2 * (recall(TP, FN)*precision(TP, FP)) / (recall(TP, FN) + precision(TP, FP)) def print_metrics(TP : int, TN : int, FP : int, FN : int): """Prints all metrics at once. :param TP: True positives :param TN: True negatives :param FP: False positives :param FN: False negatives """ print(f"Accuracy: {accuracy(TP, TN, FP, FN)}") print(f"Precision: {precision(TP, FP)}") print(f"Recall: {recall(TP, FN)}") print(f"F1-Score: {f1_score(TP, FP, FN)}") if __name__ == "__main__": print_metrics(25, 65, 5, 5) \ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!