Merge pull request 'read csv with training data' (#27) from read_training_data into master
Reviewed-on: #27
This commit is contained in:
commit
c8bcea171e
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