read csv with training data #27

Merged
s473616 merged 1 commits from read_training_data into master 2023-05-27 11:34:58 +02:00
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import os
from trainingData import TrainingData
def _read_training_data() -> TrainingData:
attributes: list[list[str]] = []
classes: list[str] = []
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
file = open(os.path.join(__location__, 'training_data.csv'))
lines = file.readlines()[1:]
file.close()
for line in lines:
actual_row = line.replace('\n', '')
values = actual_row.split(',')
line_attributes = values[:-1]
line_class = values[-1]
attributes.append(line_attributes)
classes.append(line_class)
return TrainingData(attributes, classes)
trainning_data = _read_training_data()

View File

@ -0,0 +1,7 @@
class TrainingData:
attributes: list[list[str]]
classes: list[str]
def __init__(self, attributes: list[list[str]], classes: list[str]) -> None:
self.attributes = attributes
self.classes = classes