Compare commits
No commits in common. "6feaab7f68c177a9c52c4f045c6701dae80472f4" and "12ad80a09245b1137e8fe9add55c97c960bafbce" have entirely different histories.
6feaab7f68
...
12ad80a092
@ -1,13 +1,8 @@
|
|||||||
from sklearn import tree
|
from sklearn import tree
|
||||||
from sklearn import metrics
|
|
||||||
from sklearn import preprocessing
|
|
||||||
from sklearn.ensemble import RandomForestClassifier
|
|
||||||
# from ...helpers.treenum import Tree
|
# from ...helpers.treenum import Tree
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import csv
|
import csv
|
||||||
import random
|
import random
|
||||||
from matplotlib import pyplot as plt
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
SIFT_PATH = "..\\algorithms\\data\\sift.csv"
|
SIFT_PATH = "..\\algorithms\\data\\sift.csv"
|
||||||
|
|
||||||
@ -25,49 +20,34 @@ class Tree(Enum):
|
|||||||
# [tree1_label, tree2_label]
|
# [tree1_label, tree2_label]
|
||||||
|
|
||||||
labels = []
|
labels = []
|
||||||
|
dialect = csv.Dialect
|
||||||
i = 0
|
i = 0
|
||||||
done = False
|
done = False
|
||||||
|
test_index = random.randint(0, 102)
|
||||||
|
print(test_index)
|
||||||
|
|
||||||
with open(SIFT_PATH, 'r') as file:
|
with open(SIFT_PATH, 'r') as file:
|
||||||
reader = csv.reader(file, delimiter= ',')
|
reader = csv.reader(file, delimiter= ',')
|
||||||
matrix = list(reader)
|
matrix = list(reader)
|
||||||
|
|
||||||
data = [[] for x in range(len(matrix)-1)]
|
data = [[] for x in range(len(matrix)-1)]
|
||||||
for row in matrix[1:]:
|
for row in matrix[1:]:
|
||||||
|
## Remove test case
|
||||||
|
if i == test_index and done == False:
|
||||||
|
done = True
|
||||||
|
data.pop(i)
|
||||||
|
continue
|
||||||
|
|
||||||
## append data to lists
|
## append data to lists
|
||||||
labels.append(Tree[row[0].upper()].value)
|
labels.append(Tree[row[0].upper()].value)
|
||||||
for element in row[1:]:
|
for element in row[1:]:
|
||||||
data[i].append(float(element))
|
data[i].append(element)
|
||||||
|
|
||||||
|
## iterator
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# Werkt niet met genormaliseerde data
|
clf = tree.DecisionTreeClassifier()
|
||||||
normalized = preprocessing.normalize(data, axis=0, norm='max')
|
clf = clf.fit(data, labels)
|
||||||
norm = list(normalized.tolist())
|
# tree.plot_tree(clf)
|
||||||
|
print(Tree[matrix[test_index][0].upper()])
|
||||||
actual = []
|
result = clf.predict([matrix[test_index][1:]])
|
||||||
predicted = []
|
print(Tree(result[0]).name)
|
||||||
for i in range(75):
|
|
||||||
test_index = random.randint(1, 101)
|
|
||||||
temp_data = data.pop(test_index)
|
|
||||||
temp_label = labels.pop(test_index)
|
|
||||||
|
|
||||||
# dec_tree = tree.DecisionTreeClassifier(
|
|
||||||
# criterion='entropy',
|
|
||||||
# splitter='best')
|
|
||||||
dec_tree = RandomForestClassifier(max_depth=None)
|
|
||||||
dec_tree = dec_tree.fit(data, labels)
|
|
||||||
result = dec_tree.predict([matrix[test_index][1:]])
|
|
||||||
|
|
||||||
# normalized_list.append(temp_data)
|
|
||||||
data.append(temp_data)
|
|
||||||
labels.append(temp_label)
|
|
||||||
|
|
||||||
actual.append(temp_label)
|
|
||||||
predicted.append(result[0])
|
|
||||||
|
|
||||||
c_matrix = metrics.confusion_matrix(actual, predicted)
|
|
||||||
cm_display = metrics.ConfusionMatrixDisplay(confusion_matrix=c_matrix)
|
|
||||||
cm_display.plot()
|
|
||||||
plt.show(block=False)
|
|
||||||
# print("Testdata: \t" + Tree[matrix[test_index][0].upper()].name)
|
|
||||||
# print("Predicted: \t" + Tree(result[0]).name)
|
|
Loading…
Reference in New Issue
Block a user