added decision tree generator scaffolding

This commit is contained in:
s452645 2021-05-22 23:54:46 +02:00
parent 096d506553
commit 1f71b29604
5 changed files with 23 additions and 1 deletions

View File

@ -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()))

View File

@ -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