Commit 32df389b authored by Jakub's avatar Jakub
Browse files

Added code vor tree validation.

parent b29e5454
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -6,17 +6,16 @@ import os


def load_data(filename):
    print (os.getcwd())
    with open(filename, newline='') as csvfile:
        reader = csv.reader(csvfile)
        try:
            data = [];
            data = []
            for row in reader:
                data.append(row)
            print(data)
            return np.array(data)
        except csv.Error as e:
            sys.exit("file {}, line {}: {}".format())
            sys.exit("file {}, line {}".format(filename, row))


def plant_trees(data):
@@ -26,11 +25,22 @@ def plant_trees(data):
    return tree


def validation():
    pass
def validation(tree, data):
    confusion_matrix = np.zeros((3, 3))
    parameters = np.array(data)
    classes = data[len(data)-1]
    for parameter, pclass in zip(parameters, classes):
        result = tree.predict(parameter)
        confusion_matrix[result, pclass] += 1
    return confusion_matrix


def report(tree, confusion_matrix):
    print(tree)
    print(confusion_matrix)


def store():
def store(tree, confusion_matrix):
    pass


@@ -39,8 +49,9 @@ def main():
    print("Loading file {}".format(filename))
    data = load_data(filename)
    tree = plant_trees(data)
    validation(tree)
    store(tree)
    confusion_matrix = validation(tree)
    report(tree, confusion_matrix)
    store(tree, confusion_matrix)


if __name__ == '__main__':
+1 −1

File changed.

Contains only whitespace changes.