read csv with training data
This commit is contained in:
parent
f60ed5d28f
commit
6a05f59d97
23
machine_learning/decisionTree.py
Normal file
23
machine_learning/decisionTree.py
Normal 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()
|
||||||
|
|
7
machine_learning/trainingData.py
Normal file
7
machine_learning/trainingData.py
Normal 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
|
Loading…
Reference in New Issue
Block a user