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 i += 1
# Werkt niet met genormaliseerde data # Werkt niet met genormaliseerde data
normalized = preprocessing.normalize(data, axis=0, norm='') normalized = preprocessing.normalize(data, axis=0, norm='max')
norm = list(normalized.tolist()) 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") print("Step \t seconds/step")
for step in steps: for step in steps:
@ -78,12 +78,11 @@ for step in steps:
# model = ensemble.ExtraTreesClassifier( # model = ensemble.ExtraTreesClassifier(
# n_estimators=step # higher is better, but slower (def: 100) # n_estimators=step # higher is better, but slower (def: 100)
# ) # )
model = neighbors.KNeighborsClassifier( # model = neighbors.KNeighborsClassifier(
algorithm='auto', # algorithm='auto',
leaf_size=2, # leaf_size=2,
n_neighbors=step, # n_neighbors=step,
) # )
# model = ensemble.BaggingClassifier( # model = ensemble.BaggingClassifier(
# n_estimators=5, # n_estimators=5,
# max_samples=.5, # max_samples=.5,

View File

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

View File

@ -347,12 +347,8 @@ class CVSuite:
print(C_WARN, "KNN Model not configured!") print(C_WARN, "KNN Model not configured!")
if self.test_dectree is not None: 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", "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: else:
print(C_WARN, "Decison Tree Model not configured!") print(C_WARN, "Decison Tree Model not configured!")