From b17221c7c28c48bc15e423350668cc17ba1bb5dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Mon, 25 May 2020 02:45:13 +0200 Subject: [PATCH] Add specifying training set size when testing DT --- src/game/Game.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/game/Game.py b/src/game/Game.py index 712e8e4..82f4c72 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -68,9 +68,9 @@ class Game: if argv[2] == "-p": print("Running Decision Tree in pause mode.") self.dtRun(filesPath, True) - elif argv[2] == "-test": + elif argv[2] == "-test" and len(argv) >= 5: print("Testing Decision Tree.") - self.dtTestRun(filesPath, int(argv[3])) + self.dtTestRun(filesPath, iterations=int(argv[3]), trainingSetSize=float(argv[4])) else: print("Running Decision Tree.") self.dtRun(filesPath) @@ -364,13 +364,23 @@ class Game: geneticAlgorithmWithDecisionTree(self.map, iter, 10, dtExamples, 0.1) print("Time elapsed: ", self.pgTimer.tick() // 1000) - def dtTestRun(self, filesPath, iterations): + @staticmethod + def dtTestRun(filesPath, iterations: int, trainingSetSize: float = 0.9): + """ + + + :param filesPath: + :param iterations: + :param trainingSetSize: How many % of examples that will be read from file make as trainingSet. Value from 0 to 1. + """ # Read examples for decision tree testing examplesFilePath = str( filesPath) + os.sep + "data" + os.sep + "AI_data" + os.sep + "dt_exmpls" + os.sep + "dt_examples" examplesManager = ExamplesManager(examplesFilePath) examples = examplesManager.readExamples() - scores = testDecisionTree(examples, iterations) + + # Testing tree + scores = testDecisionTree(examples, iterations, trainingSetSize) avg = sum(scores) / iterations print("Average: {}".format(str(avg)))