Compare commits

..

No commits in common. "4aa97d72a5e84f0d384a4eccf8fbde776a9907a2" and "f58f72562ccd23036e16d79cc27e49bcecfc923f" have entirely different histories.

3 changed files with 33 additions and 42 deletions

View File

@ -46,10 +46,10 @@ with open(PATH, 'r') as file:
i += 1
# Werkt niet met genormaliseerde data
normalized = preprocessing.normalize(data, axis=0, norm='')
normalized = preprocessing.normalize(data, axis=0, norm='max')
norm = list(normalized.tolist())
steps = np.linspace(1, 12, 4, dtype=np.int64)
steps = np.linspace(1e-4, 1, 20, dtype=np.float64)
print("Step \t seconds/step")
for step in steps:
@ -78,12 +78,11 @@ for step in steps:
# model = ensemble.ExtraTreesClassifier(
# n_estimators=step # higher is better, but slower (def: 100)
# )
model = neighbors.KNeighborsClassifier(
algorithm='auto',
leaf_size=2,
n_neighbors=step,
)
# model = neighbors.KNeighborsClassifier(
# algorithm='auto',
# leaf_size=2,
# n_neighbors=step,
# )
# model = ensemble.BaggingClassifier(
# n_estimators=5,
# max_samples=.5,

View File

@ -1,22 +1,15 @@
from enum import Enum
from sklearn.preprocessing import maxabs_scale, MaxAbsScaler
from sklearn.ensemble import RandomForestClassifier
from joblib import dump, load
from sklearn import tree
import numpy as np
import csv
import argparse
import os
parser = argparse.ArgumentParser(prog='DecisionTree CLI')
parser.add_argument('-i', '--input', help='Input CSV file', required=True)
parser.add_argument('-o', '--output', help='Output model folder', required=True)
parser.add_argument(
'-m',
'--model',
help='Chosen model (\'dectree\', \'randforest\' or \'extratree\')',
required=True
)
parser.add_argument('-s', '--scaler', help='Scaler preprocesser', required=True)
parser.add_argument('-o', '--output', help='Output model file', required=True)
class Tree(Enum):
ACCASIA = 0
@ -59,18 +52,19 @@ class CVSuiteTestTree:
i += 1
# normalize data
#TODO: Arne help
if self.scaler is not None:
norm = self.scaler.fit(data)
for row in norm:
print(len(row))
else:
raise EnvironmentError("No scaler found")
# train model
self.train(data, labels, output)
self.train(norm, labels, output)
def addScaler(self, path) -> None:
self.scaler = load(path)
if self.scaler is None:
print("Scaler failed to load!")
exit()
def train(self, data, labels, output) -> None:
print("You called the parent class, doofus")
@ -81,7 +75,7 @@ class CVSuiteTestTree:
def predict(self, data) -> None | int:
if self.model is not None:
return self.model.predict(data)
return self.model.predict([data])
else:
return None
@ -116,16 +110,18 @@ class CVSuiteTestExtraTrees(CVSuiteTestTree):
if __name__ == "__main__":
args = parser.parse_args()
if args.model == 'dectree':
test = CVSuiteTestDecisionTree()
elif args.model == 'randforest':
test = CVSuiteTestRandomForest()
elif args.model == 'extratree':
test = CVSuiteTestExtraTrees()
else:
print("Model not found!")
exit()
test.addScaler(args.scaler)
test.trainCSV(args.input, args.output)
test = CVSuiteTestRandomForest()
test.trainCSV(args.input, args.output)
test = CVSuiteTestDecisionTree(
"C:\\Users\\Tom\\Desktop\\Files\\Repositories\\EV5_Beeldherk_Bomen\\models\\randomforest.joblib"
)
path = "C:\\Users\\Tom\\Desktop\\Files\\Repositories\\EV5_Beeldherk_Bomen\\dataset\\csv\\result-2023-10-21T09.59.24.csv"
file = open(path, 'r')
reader = csv.reader(file, delimiter=',')
matrix = list(reader)
file.close()
data = [float(x) for x in matrix[2][2:]]
norm = maxabs_scale(data)
print(test.predict(norm))

View File

@ -347,12 +347,8 @@ class CVSuite:
print(C_WARN, "KNN Model not configured!")
if self.test_dectree is not None:
result = self.test_dectree.predict(data)
print(self.test_dectree.predict(data))
output.insert("end", "Decision Tree Result:\n")
output.insert("end", f"\t{Tree(result).name}\n")
print(C_DBUG, "Decision Tree Result:")
print("\t\t result: \t{}".format(result))
else:
print(C_WARN, "Decison Tree Model not configured!")