splitting data_set and getting correctnes

This commit is contained in:
Denys Seredenko
2024-10-21 14:44:33 +02:00
parent dcb7cee31c
commit 2e2e627bf3
7 changed files with 1836 additions and 15 deletions

View File

@@ -7,4 +7,21 @@ class Concept(Enum):
STOP = auto()
RECHTS_ABBIEGEN = auto()
LINKS_ABBIEGEN = auto()
RECHTS_VOR_LINKS = auto()
RECHTS_VOR_LINKS = auto()
def identify_by_str(name: str):
match name:
case 'VORFAHRT_GEWAEHREN':
return Concept.VORFAHRT_GEWAEHREN
case 'VORFAHRT_STRASSE':
return Concept.VORFAHRT_STRASSE
case 'STOP':
return Concept.STOP
case 'RECHTS_ABBIEGEN':
return Concept.RECHTS_ABBIEGEN
case 'LINKS_ABBIEGEN':
return Concept.LINKS_ABBIEGEN
case 'RECHTS_VOR_LINKS':
return Concept.RECHTS_VOR_LINKS
case _:
return Concept.UNKNOWN

View File

@@ -6,12 +6,15 @@ from classes.concept import Concept
from classes.feature_vector import FeatureVector
class Learner:
def __init__(self, k_paramater: int) -> None:
self.k_paramter = k_paramater
# The training method, that changes the internal state of the learner such that
# it will classify examples of a similar set (i.e. the testSet better.
#
# @param trainingSet contains feature vectors and corresponding concepts
# to provide experience to learn from
def learn(self, path_to_training_set: str):
training_set = []
with open(path_to_training_set, mode='r' ,newline='') as csv_file:
@@ -45,8 +48,7 @@ class Learner:
distances.append((single_fv.get_concept(), single_dist))
sorted_distances = sorted(distances, key=lambda tuple: tuple[1])
k_nearest = 3
interested_distances = sorted_distances[:k_nearest]
interested_distances = sorted_distances[:self.k_paramter]
for interested_fv in interested_distances:
concept = self.string_to_enum(Concept, interested_fv[0])
@@ -76,8 +78,13 @@ class Learner:
print(f"Error: {e}")
return None
def analyse(self, result, k):
sorted_dict_result = {key: value for key, value in sorted(result.items(), key=lambda item: item[1])}
def analyse(self, result, expectedConcept: Concept):
sorted_dict_result = {key: value for key, value in sorted(result.items(), reverse=True, key=lambda item: item[1])}
for key, amount in sorted_dict_result.items():
probability = (amount/k) * 100
print(f" Probability of {key} is {probability}%")
probability = (amount/self.k_paramter) * 100
print(f" Probability of {key} is {probability}%")
if next(iter(sorted_dict_result)) == expectedConcept:
return 1
else:
return 0