From 1f71b29604895355c39e6aee4fab3e43520c3d4e Mon Sep 17 00:00:00 2001 From: s452645 Date: Sat, 22 May 2021 23:54:46 +0200 Subject: [PATCH] added decision tree generator scaffolding --- .../learning_algorithms/decision_tree.py | 22 +++++++++++++++++++ .../searching_algorithms}/a_star.py | 0 .../searching_algorithms}/bfs.py | 0 main.py | 2 +- searching_algorithms/__init__.py | 0 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 algorithms/learning_algorithms/decision_tree.py rename {searching_algorithms => algorithms/searching_algorithms}/a_star.py (100%) rename {searching_algorithms => algorithms/searching_algorithms}/bfs.py (100%) delete mode 100644 searching_algorithms/__init__.py diff --git a/algorithms/learning_algorithms/decision_tree.py b/algorithms/learning_algorithms/decision_tree.py new file mode 100644 index 0000000..25e894a --- /dev/null +++ b/algorithms/learning_algorithms/decision_tree.py @@ -0,0 +1,22 @@ +from joblib import dump, load +from sklearn import tree +from sklearn.feature_extraction import DictVectorizer + +# X is a list of dictionaries with samples, Y is a list of samples' results +X = list() +Y = list() + +# TODO: load training data + +# vec transforms X (a list of dictionaries of string-string pairs) to binary arrays for tree to work on +vec = DictVectorizer() + +# create and run Tree Clasifier upon provided data +clf = tree.DecisionTreeClassifier(max_depth=3) +clf = clf.fit(vec.fit_transform(X).toarray(), Y) + +# save decision tree to file +dump(clf, 'decision_tree.joblib') + +# print a tree (not necessary) +print(tree.export_text(clf, feature_names=vec.get_feature_names())) diff --git a/searching_algorithms/a_star.py b/algorithms/searching_algorithms/a_star.py similarity index 100% rename from searching_algorithms/a_star.py rename to algorithms/searching_algorithms/a_star.py diff --git a/searching_algorithms/bfs.py b/algorithms/searching_algorithms/bfs.py similarity index 100% rename from searching_algorithms/bfs.py rename to algorithms/searching_algorithms/bfs.py diff --git a/main.py b/main.py index efacc6c..73ee9b5 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ import project_constants as const import minefield as mf from mines.mine_models.time_mine import TimeMine -import searching_algorithms.a_star as a_star +import algorithms.searching_algorithms.a_star as a_star from display_assets import blit_graphics diff --git a/searching_algorithms/__init__.py b/searching_algorithms/__init__.py deleted file mode 100644 index e69de29..0000000