read csv with training data

This commit is contained in:
Pawel Felcyn 2023-05-27 11:34:26 +02:00
parent f60ed5d28f
commit 6a05f59d97
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