From 8103eabd8f6ba03ff9b4f893ab2d32783d7bb503 Mon Sep 17 00:00:00 2001 From: Fabian Poker <fp168637@fh-muenster.de> Date: Sun, 7 May 2023 21:22:31 +0200 Subject: [PATCH] Evaluation --- aufgaben/p5/pla_applied.py | 68 ++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/aufgaben/p5/pla_applied.py b/aufgaben/p5/pla_applied.py index 306838d..e8c6518 100644 --- a/aufgaben/p5/pla_applied.py +++ b/aufgaben/p5/pla_applied.py @@ -1,3 +1,5 @@ +import math + from algorithm.pla.perceptron_learning_algorithm import train, train_pocket from algorithm.pla.perceptron import Perceptron from algorithm.pla.transfer_functions import normalized_tanh @@ -26,10 +28,37 @@ def apply_pla(): max_iterations = 100 learning_rate = 0.10 train(perceptron, training_data, max_iterations, learning_rate) - print("\nPLA: Zunächst Gewichte, dann Klassifizierung. Erwartet: 1 & 0") + print("\nPLA: Zunächst Gewichte, dann Klassifizierung. Gehen = 1, Kniebeuge = 0") print(perceptron.weights) - print(perceptron.classify(joggen.werte[15:18].tolist())) - print(perceptron.classify(kniebeuge.werte[55:58].tolist())) + cnt_true_pos = 0 + cnt_true_neg = 0 + cnt_false_pos = 0 + cnt_false_neg = 0 + unclassified = 0 + for i in range(500): + jog_res = perceptron.classify(joggen.werte[i:i+3].tolist()) + knie_res = perceptron.classify(kniebeuge.werte[i:i+3].tolist()) + if math.isclose(1, jog_res, abs_tol=0.1): + cnt_true_pos += 1 + elif math.isclose(0, jog_res, abs_tol=0.1): + cnt_false_neg += 1 + else: + unclassified += 1 + if math.isclose(0, knie_res, abs_tol=0.1): + cnt_true_neg += 1 + elif math.isclose(1, knie_res, abs_tol=0.1): + cnt_false_pos += 1 + else: + unclassified += 1 + print(f""" + Anzahl Prüfungen: 1000 + True Positive: {cnt_true_pos} + False Positive: {cnt_false_pos} + True Negative: {cnt_true_neg} + False Negative: {cnt_false_neg} + Unclassifiable: {unclassified} + Fehlerrate: {(cnt_false_neg+cnt_false_pos) / 10}% bzw. {(cnt_false_neg+cnt_false_pos+unclassified) / 10}% + """) def apply_pocket(): @@ -54,10 +83,37 @@ def apply_pocket(): max_iterations = 1 learning_rate = 0.10 train_pocket(perceptron, training_data, max_iterations, learning_rate) - print("\nPocket: Zunächst Gewichte, dann Klassifizierung. Erwartet: 1 & 0") + print("\nPocket: Zunächst Gewichte, dann Klassifizierung. Gehen = 1, Kniebeuge = 0") print(perceptron.weights) - print(perceptron.classify(joggen.werte[15:18].tolist())) - print(perceptron.classify(kniebeuge.werte[55:58].tolist())) + cnt_true_pos = 0 + cnt_true_neg = 0 + cnt_false_pos = 0 + cnt_false_neg = 0 + unclassified = 0 + for i in range(500): + jog_res = perceptron.classify(joggen.werte[i:i+3].tolist()) + knie_res = perceptron.classify(kniebeuge.werte[i:i+3].tolist()) + if math.isclose(1, jog_res, abs_tol=0.1): + cnt_true_pos += 1 + elif math.isclose(0, jog_res, abs_tol=0.1): + cnt_false_neg += 1 + else: + unclassified += 1 + if math.isclose(0, knie_res, abs_tol=0.1): + cnt_true_neg += 1 + elif math.isclose(1, knie_res, abs_tol=0.1): + cnt_false_pos += 1 + else: + unclassified += 1 + print(f""" + Anzahl Prüfungen: 1000 + True Positive: {cnt_true_pos} + False Positive: {cnt_false_pos} + True Negative: {cnt_true_neg} + False Negative: {cnt_false_neg} + Unclassifiable: {unclassified} + Fehlerrate: {(cnt_false_neg+cnt_false_pos) / 10}% bzw. {(cnt_false_neg+cnt_false_pos+unclassified) / 10}% + """) if __name__ == '__main__': -- GitLab