Skip to content
Snippets Groups Projects
Commit 8c470359 authored by Fabian Poker's avatar Fabian Poker
Browse files

Evaluation better

parent f5b2bc57
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import random
from algorithm.pla.perceptron_learning_algorithm import train, train_pocket
from algorithm.pla.perceptron import Perceptron
from algorithm.pla.transfer_functions import normalized_tanh
from aufgaben.p6.evaluate import evaluate
from korpus import create_bewegung
......@@ -31,35 +32,14 @@ def apply_pla():
train(perceptron, training_data, max_iterations, learning_rate)
print("\nPLA: Zunächst Gewichte, dann Klassifizierung. Gehen = 1, Kniebeuge = 0")
print(perceptron.weights)
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.sensoren[0].werte[i], joggen.sensoren[1].werte[i], joggen.sensoren[2].werte[i]])
knie_res = perceptron.classify([kniebeuge.sensoren[0].werte[i], kniebeuge.sensoren[1].werte[i], kniebeuge.sensoren[2].werte[i]])
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}%
""")
amount_of_weights = 3
correct_data = []
incorrect_data = []
for i in range(amount_of_weights):
correct_data.append(joggen.sensoren[i].werte)
incorrect_data.append(kniebeuge.sensoren[i].werte)
evaluate(500, amount_of_weights, correct_data, incorrect_data, perceptron)
def apply_pocket():
......@@ -86,37 +66,13 @@ def apply_pocket():
train_pocket(perceptron, training_data, max_iterations, learning_rate)
print("\nPocket: Zunächst Gewichte, dann Klassifizierung. Gehen = 1, Kniebeuge = 0")
print(perceptron.weights)
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.sensoren[0].werte[i], joggen.sensoren[1].werte[i], joggen.sensoren[2].werte[i]])
knie_res = perceptron.classify(
[kniebeuge.sensoren[0].werte[i], kniebeuge.sensoren[1].werte[i], kniebeuge.sensoren[2].werte[i]])
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}%
""")
amount_of_weights = 3
correct_data = []
incorrect_data = []
for i in range(amount_of_weights):
correct_data.append(joggen.sensoren[i].werte)
incorrect_data.append(kniebeuge.sensoren[i].werte)
evaluate(500, amount_of_weights, correct_data, incorrect_data, perceptron)
if __name__ == '__main__':
......
import math
from algorithm.pla.perceptron import Perceptron
def evaluate(iterations: int, amount_of_values: int, correct_data: list, incorrect_data: list, perceptron: Perceptron):
cnt_true_pos = 0
cnt_true_neg = 0
cnt_false_pos = 0
cnt_false_neg = 0
unclassified = 0
for i in range(500):
corr = []
incorr = []
for j in range(amount_of_values):
corr.append(correct_data[j][i])
incorr.append(incorrect_data[j][i])
jog_res = perceptron.classify(corr)
knie_res = perceptron.classify(incorr)
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: {iterations*2}
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}%
""")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment