diff --git a/aufgaben/p5/pla_applied.py b/aufgaben/p5/pla_applied.py index 306838d666b4049300f6ff0a57646d5400730258..e8c6518090f009e5d7324d11df20c691deffdd47 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__':