added decision tree generator scaffolding
This commit is contained in:
parent
096d506553
commit
1f71b29604
22
algorithms/learning_algorithms/decision_tree.py
Normal file
22
algorithms/learning_algorithms/decision_tree.py
Normal 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()))
|
2
main.py
2
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user