Drzewo decyzyjne

This commit is contained in:
Miron 2021-05-23 20:27:48 +02:00
parent 4b8bc07c77
commit 351af34703
11 changed files with 652 additions and 59 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,14 +1,15 @@
Sh = 200
St = 10
WAREHOUSE_MAP = [ WAREHOUSE_MAP = [
[0, 0, 0, 10, 10, 0, 0, 0, 0], [0, 0, 0, St, St, 0, 0, 0, 0],
[0, 10, 0, 10, 0, 10, 0, 0, 0], [0, St, 0, St, 0, St, 0, 0, 0],
[0, 10, 0, 0, 0, 200, 200, 200, 200], [0, St, 0, 0, 0, Sh, Sh, Sh, Sh],
[0, 0, 10, 0, 0, 0, 0, 0, 0], [0, 0, St, 0, 0, 0, 0, 0, 0],
[0, 0, 10, 0, 0, 200, 200, 200, 200], [0, 0, St, 0, 0, Sh, Sh, Sh, Sh],
[0, 0, 10, 10, 0, 0, 0, 0, 0], [0, 0, St, St, 0, 0, 0, 0, 0],
[10, 0, 0, 0, 10, 200, 200, 200, 200], [St, 0, 0, 0, St, Sh, Sh, Sh, Sh],
[0, 0, 10, 10, 10, 0, 0, 0, 0], [0, 0, St, St, St, 0, 0, 0, 0],
[0, 10, 0, 0, 0, 200, 200, 200, 200], [0, St, 0, 0, 0, Sh, Sh, Sh, Sh],
] ]

View File

@ -2,7 +2,7 @@ import pygame
import random import random
import time import time
from src.a_star import a_star_search, WAREHOUSE_MAP from src.a_star import a_star_search, WAREHOUSE_MAP, St
from src.bfs import breadth_first_search from src.bfs import breadth_first_search
pygame.init() pygame.init()
@ -45,7 +45,7 @@ def generate_package(a, b):
image_list = ['img/package_grocery.png', 'img/package_explosive.png', 'img/package.png', 'img/package_builders.png'] image_list = ['img/package_grocery.png', 'img/package_explosive.png', 'img/package.png', 'img/package_builders.png']
p1 = Package((a, b), rand_x, name_list[rand_y - 1], image_list[rand_y - 1]) p1 = Package((a, b), rand_x, name_list[rand_y - 1], image_list[rand_y - 1])
return p1 return p1
class Package: class Package:
def __init__(self, pos, content, content_size, pack_image): def __init__(self, pos, content, content_size, pack_image):
@ -197,25 +197,21 @@ Package_list = [
] ]
print(a_star_search((6, 8), (0, 0), "down")) #print(a_star_search((6, 8), (0, 0), "down"))
#agent.path = breadth_first_search(agent.pos_coord, agent.goal, agent.agent_direction)
agent.path = a_star_search((agent.pos_coord[1], agent.pos_coord[0]), (0, 0), agent.agent_direction) agent.path = a_star_search((agent.pos_coord[1], agent.pos_coord[0]), (0, 0), agent.agent_direction)
#print(agent.path)
# Pętla służąca do tworzenia plam oleju na podstawie mapy magazynu # Pętla służąca do tworzenia plam oleju na podstawie mapy magazynu
Stain_list = [] Stain_list = []
for index_x in range(9): for index_x in range(9):
for index_y in range(9): for index_y in range(9):
if WAREHOUSE_MAP[index_x][index_y] == 10: if WAREHOUSE_MAP[index_x][index_y] == St:
Stain_list.append(Stain((index_y, index_x))) Stain_list.append(Stain((index_y, index_x)))
running = True running = True
while running: while running:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
running = False running = False

View File

@ -0,0 +1,200 @@
10,2,2,0,0,4,0
1,1,4,0,0,5,1
5,1,10,0,0,10,0
2,1,2,0,0,3,1
1,4,9,3,5,3,0
1,4,2,4,5,2,0
5,2,7,0,0,1,1
1,3,4,0,0,7,1
1,1,2,0,0,4,1
2,4,8,3,4,2,1
1,2,2,0,2,3,1
5,3,5,4,0,3,1
9,3,3,0,0,2,0
6,1,1,0,0,5,1
2,1,3,0,0,1,1
1,3,8,0,0,6,1
5,2,1,3,1,5,1
3,4,1,5,4,5,0
3,4,7,5,5,1,0
3,3,2,0,0,10,0
1,2,6,0,0,8,1
9,4,8,5,4,1,0
6,4,3,3,5,5,1
2,2,9,0,0,3,0
5,4,2,3,5,5,1
4,3,6,3,0,9,0
5,4,2,4,3,4,1
4,4,1,5,5,2,0
5,3,3,0,0,1,1
5,2,3,0,0,7,1
2,2,1,5,0,4,1
1,1,7,0,0,5,1
3,2,4,2,0,5,1
9,2,4,0,0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 0 2 9 0
112 5 1 2 0 0 5 1
113 4 4 7 3 3 3 0
114 1 4 7 4 4 1 0
115 3 1 4 0 0 1 1
116 1 3 3 0 0 4 1
117 6 1 6 0 0 2 1
118 10 1 2 0 0 5 1
119 7 1 3 0 0 4 1
120 7 3 4 0 0 8 1
121 1 3 7 0 0 2 1
122 4 1 6 0 0 5 1
123 1 3 2 0 0 1 1
124 3 4 5 4 3 2 1
125 2 1 2 0 0 1 1
126 1 3 3 0 2 2 1
127 4 4 5 4 3 5 1
128 7 3 10 0 0 2 0
129 2 3 8 3 0 4 1
130 4 3 1 0 0 2 1
131 2 3 3 0 0 5 1
132 3 2 7 0 0 3 1
133 5 2 7 0 0 8 1
134 2 2 10 3 0 1 0
135 2 2 1 2 0 9 1
136 2 2 1 3 0 2 1
137 4 4 5 3 3 3 1
138 1 4 1 3 5 5 0
139 2 1 3 0 0 4 1
140 4 3 7 0 0 4 1
141 2 1 7 0 0 5 1
142 4 1 1 0 0 5 1
143 4 4 7 3 5 4 0
144 5 2 5 0 0 3 1
145 1 3 7 0 0 4 1
146 10 3 6 1 0 7 1
147 3 2 5 5 0 8 0
148 1 1 1 0 0 1 1
149 3 3 6 0 0 3 1
150 2 3 3 0 0 5 1
151 4 2 3 0 1 10 1
152 4 2 2 0 0 5 1
153 3 3 7 0 0 5 1
154 3 2 6 5 0 2 0
155 9 2 1 5 1 3 0
156 7 1 8 0 0 1 0
157 2 1 9 0 0 3 0
158 6 3 1 4 0 9 1
159 4 3 5 0 0 4 1
160 5 4 6 3 3 5 1
161 1 2 10 2 0 3 0
162 3 3 2 2 0 5 1
163 3 1 10 0 0 1 1
164 10 1 7 0 0 4 0
165 7 4 2 3 3 4 0
166 8 2 7 2 0 4 1
167 4 3 1 0 0 10 0
168 5 2 1 0 0 9 0
169 6 3 4 0 0 4 1
170 2 1 2 0 0 1 1
171 9 3 1 0 0 4 0
172 4 1 6 0 0 3 1
173 4 2 7 0 0 5 1
174 4 2 7 0 0 3 1
175 4 2 5 0 1 2 1
176 4 1 2 0 0 1 1
177 1 1 9 0 0 4 0
178 2 3 5 0 0 2 1
179 5 1 7 0 0 2 1
180 1 2 1 0 0 1 1
181 2 3 5 0 0 8 0
182 3 3 5 0 0 4 1
183 4 4 9 5 5 10 0
184 3 2 3 1 0 4 1
185 1 1 7 0 0 4 1
186 2 2 4 0 0 10 0
187 7 4 1 3 2 3 0
188 9 1 1 0 0 1 1
189 4 1 7 0 0 4 1
190 5 1 5 0 0 1 1
191 3 2 2 3 2 2 1
192 2 1 7 0 0 5 1
193 1 2 3 0 2 4 1
194 9 2 5 0 0 2 0
195 4 3 8 5 0 5 0
196 2 2 6 4 0 1 1
197 3 3 4 0 2 3 1
198 1 3 5 0 0 4 1
199 2 4 4 3 3 9 0
200 1 2 6 0 0 2 1

View File

@ -1,3 +1,4 @@
# DICT 1-groceries 2-builders 3-electronics 4-dangerous
# POZIOM WAGI(1-10), TYP, STOPIEN ROZMIARU(1-10), STOPIEN LATWOPALNOSCI(0-5), STOPIEN WYBUCHOWOSCI(0-5), POZIOM CENY(1-10), PRZYJETY DO MAGAZYNU(tak, nie) # POZIOM WAGI(1-10), TYP, STOPIEN ROZMIARU(1-10), STOPIEN LATWOPALNOSCI(0-5), STOPIEN WYBUCHOWOSCI(0-5), POZIOM CENY(1-10), PRZYJETY DO MAGAZYNU(tak, nie)
# SZYMON \/ # SZYMON \/
#|WAGA|TYP|WYMIAR|LATWOPALNOSC|WYBUCHOWOSC|CENA|PRZYJETY_DO_MAGAZYNU #|WAGA|TYP|WYMIAR|LATWOPALNOSC|WYBUCHOWOSC|CENA|PRZYJETY_DO_MAGAZYNU
@ -131,46 +132,46 @@
# BOGDAN \/ # BOGDAN \/
#|WAGA|TYP|WYMIAR|LATWOPALNOSC|WYBUCHOWOSC|CENA|PRZYJETY_DO_MAGAZYNU #|WAGA|TYP|WYMIAR|LATWOPALNOSC|WYBUCHOWOSC|CENA|PRZYJETY_DO_MAGAZYNU
# #
1 builders 10 2 0 3 1 builders 10 2 0 3 nie
3 electronics 2 2 0 5 3 electronics 2 2 0 5 tak
3 groceries 10 0 0 1 3 groceries 10 0 0 1 tak
10 groceries 7 0 0 4 10 groceries 7 0 0 4 nie
7 dangerous 2 3 3 4 7 dangerous 2 3 3 4 nie
8 builders 7 2 0 4 8 builders 7 2 0 4 tak
4 electronics 1 0 0 10 4 electronics 1 0 0 10
5 builders 1 0 0 9 5 builders 1 0 0 9 nie
6 electronics 4 0 0 4 6 electronics 4 0 0 4 tak
2 groceries 2 0 0 1 2 groceries 2 0 0 1 tak
9 electronics 1 0 0 4 9 electronics 1 0 0 4 nie
4 groceries 6 0 0 3 4 groceries 6 0 0 3 tak
4 builders 7 0 0 5 4 builders 7 0 0 5 tak
4 builders 7 0 0 3 4 builders 7 0 0 3 tak
4 builders 5 0 1 2 4 builders 5 0 1 2 tak
4 groceries 2 0 0 1 4 groceries 2 0 0 1 tak
1 groceries 9 0 0 4 1 groceries 9 0 0 4 nie
2 electronics 5 0 0 2 2 electronics 5 0 0 2 tak
5 groceries 7 0 0 2 5 groceries 7 0 0 2 tak
1 builders 1 0 0 1 1 builders 1 0 0 1 tak
2 electronics 5 0 0 8 2 electronics 5 0 0 8 nie
3 electronics 5 0 0 4 3 electronics 5 0 0 4 tak
4 dangerous 9 5 5 10 4 dangerous 9 5 5 10 nie
3 builders 3 1 0 4 3 builders 3 1 0 4 tak
1 groceries 7 0 0 4 1 groceries 7 0 0 4 tak
2 builders 4 0 0 10 2 builders 4 0 0 10 nie
7 dangerous 1 3 2 3 7 dangerous 1 3 2 3 nie
9 groceries 1 0 0 1 9 groceries 1 0 0 1 tak
4 groceries 7 0 0 4 4 groceries 7 0 0 4 tak
5 groceries 5 0 0 1 5 groceries 5 0 0 1 tak
3 builders 2 3 2 2 3 builders 2 3 2 2 tak
2 groceries 7 0 0 5 2 groceries 7 0 0 5 tak
1 builders 3 0 2 4 1 builders 3 0 2 4 tak
9 builders 5 0 0 2 9 builders 5 0 0 2 nie
4 electronics 8 5 0 5 4 electronics 8 5 0 5 nie
2 builders 6 4 0 1 2 builders 6 4 0 1 tak
3 electronics 4 0 2 3 3 electronics 4 0 2 3 tak
1 electronics 5 0 0 4 1 electronics 5 0 0 4 tak
2 dangerous 4 3 3 9 2 dangerous 4 3 3 9 nie
1 builders 6 0 0 2 1 builders 6 0 0 2 tak
# MACIEJ \/ # MACIEJ \/
#|WAGA|TYP|WYMIAR|LATWOPALNOSC|WYBUCHOWOSC|CENA|PRZYJETY_DO_MAGAZYNU #|WAGA|TYP|WYMIAR|LATWOPALNOSC|WYBUCHOWOSC|CENA|PRZYJETY_DO_MAGAZYNU
# #

View File

@ -0,0 +1,201 @@
weight type size inflammability explosiveness prize allowed_in
10 2 2 0 0 4 0
1 1 4 0 0 5 1
5 1 10 0 0 10 0
2 1 2 0 0 3 1
1 4 9 3 5 3 0
1 4 2 4 5 2 0
5 2 7 0 0 1 1
1 3 4 0 0 7 1
1 1 2 0 0 4 1
2 4 8 3 4 2 1
1 2 2 0 2 3 1
5 3 5 4 0 3 1
9 3 3 0 0 2 0
6 1 1 0 0 5 1
2 1 3 0 0 1 1
1 3 8 0 0 6 1
5 2 1 3 1 5 1
3 4 1 5 4 5 0
3 4 7 5 5 1 0
3 3 2 0 0 10 0
1 2 6 0 0 8 1
9 4 8 5 4 1 0
6 4 3 3 5 5 1
2 2 9 0 0 3 0
5 4 2 3 5 5 1
4 3 6 3 0 9 0
5 4 2 4 3 4 1
4 4 1 5 5 2 0
5 3 3 0 0 1 1
5 2 3 0 0 7 1
2 2 1 5 0 4 1
1 1 7 0 0 5 1
3 2 4 2 0 5 1
9 2 4 0 0 3 0
10 1 5 0 0 3 0
5 4 10 3 5 5 0
4 3 3 0 0 4 1
1 2 3 2 0 9 1
4 1 3 0 0 2 1
10 3 3 0 0 3 0
10 2 1 0 0 5 0
4 4 5 3 2 2 0
2 3 1 0 0 4 1
8 4 7 5 4 7 0
3 3 7 1 0 4 1
4 3 7 4 0 3 1
4 2 6 0 0 2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 5 0 0 2 0
4 3 8 5 0 5 0
2 2 6 4 0 1 1
3 3 4 0 2 3 1
1 3 5 0 0 4 1
2 4 4 3 3 9 0
1 2 6 0 0 2 1

52
src/tree.py Normal file
View File

@ -0,0 +1,52 @@
import joblib
import matplotlib.pyplot as plt
import pandas
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
columns = ["weight", "type", "size", "inflammability", "explosiveness", "prize", "allowed_in"]
attributes = ["weight", "type", "size", "inflammability", "explosiveness", "prize"]
decisions = ["allowed_in"]
def learning_tree():
dataset = pandas.read_csv('./training_data/scripts/data/training_list_id3.csv', header=None, names=columns)
dataset.head()
x = dataset[attributes]
y = dataset.allowed_in
decision_tree = DecisionTreeClassifier()
decision_tree = decision_tree.fit(x, y)
return decision_tree
def making_decision(decision_tree, weight, type, size, inflammability, explosiveness, prize):
decision = decision_tree.predict([[weight, type, size, inflammability, explosiveness, prize]])
return decision
def save_all(decision_tree):
save_tree_to_png(decision_tree)
save_tree_to_txt(decision_tree)
save_tree_to_structure(decision_tree)
def save_tree_to_txt(decision_tree):
with open('tree/tree_in_txt.txt', "w") as file:
file.write(tree.export_text(decision_tree))
def save_tree_to_png(decision_tree):
fig = plt.figure(figsize=(25, 20))
_ = tree.plot_tree(decision_tree, feature_names=attributes, filled=True)
fig.savefig('tree/decision_tree.png')
def save_tree_to_structure(decision_tree):
joblib.dump(decision_tree, 'tree/tree_model')
def load_tree_from_structure(file):
return joblib.load(file)

BIN
src/tree/decision_tree.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 KiB

142
src/tree/tree_in_txt.txt Normal file
View File

@ -0,0 +1,142 @@
|--- feature_3 <= 2.50
| |--- feature_5 <= 9.50
| | |--- feature_0 <= 8.50
| | | |--- feature_2 <= 7.50
| | | | |--- feature_5 <= 7.50
| | | | | |--- feature_2 <= 2.50
| | | | | | |--- feature_1 <= 2.50
| | | | | | | |--- class: 1
| | | | | | |--- feature_1 > 2.50
| | | | | | | |--- feature_2 <= 1.50
| | | | | | | | |--- class: 1
| | | | | | | |--- feature_2 > 1.50
| | | | | | | | |--- feature_5 <= 3.00
| | | | | | | | | |--- class: 1
| | | | | | | | |--- feature_5 > 3.00
| | | | | | | | | |--- feature_3 <= 1.00
| | | | | | | | | | |--- class: 0
| | | | | | | | | |--- feature_3 > 1.00
| | | | | | | | | | |--- class: 1
| | | | | |--- feature_2 > 2.50
| | | | | | |--- class: 1
| | | | |--- feature_5 > 7.50
| | | | | |--- feature_3 <= 0.50
| | | | | | |--- feature_2 <= 2.50
| | | | | | | |--- class: 0
| | | | | | |--- feature_2 > 2.50
| | | | | | | |--- feature_0 <= 3.50
| | | | | | | | |--- feature_2 <= 5.50
| | | | | | | | | |--- class: 0
| | | | | | | | |--- feature_2 > 5.50
| | | | | | | | | |--- class: 1
| | | | | | | |--- feature_0 > 3.50
| | | | | | | | |--- class: 1
| | | | | |--- feature_3 > 0.50
| | | | | | |--- class: 1
| | | |--- feature_2 > 7.50
| | | | |--- feature_1 <= 2.50
| | | | | |--- feature_2 <= 9.50
| | | | | | |--- class: 0
| | | | | |--- feature_2 > 9.50
| | | | | | |--- feature_5 <= 2.00
| | | | | | | |--- class: 1
| | | | | | |--- feature_5 > 2.00
| | | | | | | |--- class: 0
| | | | |--- feature_1 > 2.50
| | | | | |--- feature_2 <= 9.00
| | | | | | |--- class: 1
| | | | | |--- feature_2 > 9.00
| | | | | | |--- class: 0
| | |--- feature_0 > 8.50
| | | |--- feature_5 <= 1.50
| | | | |--- class: 1
| | | |--- feature_5 > 1.50
| | | | |--- feature_5 <= 6.50
| | | | | |--- feature_2 <= 4.50
| | | | | | |--- feature_1 <= 1.50
| | | | | | | |--- feature_0 <= 9.50
| | | | | | | | |--- class: 0
| | | | | | | |--- feature_0 > 9.50
| | | | | | | | |--- class: 1
| | | | | | |--- feature_1 > 1.50
| | | | | | | |--- class: 0
| | | | | |--- feature_2 > 4.50
| | | | | | |--- feature_1 <= 2.50
| | | | | | | |--- class: 0
| | | | | | |--- feature_1 > 2.50
| | | | | | | |--- feature_4 <= 1.00
| | | | | | | | |--- class: 1
| | | | | | | |--- feature_4 > 1.00
| | | | | | | | |--- class: 0
| | | | |--- feature_5 > 6.50
| | | | | |--- class: 1
| |--- feature_5 > 9.50
| | |--- feature_4 <= 0.50
| | | |--- class: 0
| | |--- feature_4 > 0.50
| | | |--- class: 1
|--- feature_3 > 2.50
| |--- feature_3 <= 4.50
| | |--- feature_2 <= 8.50
| | | |--- feature_0 <= 1.50
| | | | |--- feature_1 <= 3.50
| | | | | |--- feature_5 <= 3.00
| | | | | | |--- class: 1
| | | | | |--- feature_5 > 3.00
| | | | | | |--- class: 0
| | | | |--- feature_1 > 3.50
| | | | | |--- class: 0
| | | |--- feature_0 > 1.50
| | | | |--- feature_0 <= 6.50
| | | | | |--- feature_0 <= 4.50
| | | | | | |--- feature_5 <= 7.00
| | | | | | | |--- feature_0 <= 2.50
| | | | | | | | |--- class: 1
| | | | | | | |--- feature_0 > 2.50
| | | | | | | | |--- feature_2 <= 6.00
| | | | | | | | | |--- feature_4 <= 2.50
| | | | | | | | | | |--- feature_1 <= 3.00
| | | | | | | | | | | |--- class: 1
| | | | | | | | | | |--- feature_1 > 3.00
| | | | | | | | | | | |--- class: 0
| | | | | | | | | |--- feature_4 > 2.50
| | | | | | | | | | |--- class: 1
| | | | | | | | |--- feature_2 > 6.00
| | | | | | | | | |--- feature_3 <= 3.50
| | | | | | | | | | |--- class: 0
| | | | | | | | | |--- feature_3 > 3.50
| | | | | | | | | | |--- feature_0 <= 3.50
| | | | | | | | | | | |--- class: 0
| | | | | | | | | | |--- feature_0 > 3.50
| | | | | | | | | | | |--- class: 1
| | | | | | |--- feature_5 > 7.00
| | | | | | | |--- class: 0
| | | | | |--- feature_0 > 4.50
| | | | | | |--- class: 1
| | | | |--- feature_0 > 6.50
| | | | | |--- feature_5 <= 2.50
| | | | | | |--- feature_4 <= 4.50
| | | | | | | |--- class: 1
| | | | | | |--- feature_4 > 4.50
| | | | | | | |--- class: 0
| | | | | |--- feature_5 > 2.50
| | | | | | |--- class: 0
| | |--- feature_2 > 8.50
| | | |--- class: 0
| |--- feature_3 > 4.50
| | |--- feature_0 <= 2.50
| | | |--- feature_2 <= 2.50
| | | | |--- class: 1
| | | |--- feature_2 > 2.50
| | | | |--- class: 0
| | |--- feature_0 > 2.50
| | | |--- feature_4 <= 0.50
| | | | |--- feature_0 <= 5.50
| | | | | |--- class: 0
| | | | |--- feature_0 > 5.50
| | | | | |--- feature_0 <= 8.00
| | | | | | |--- class: 1
| | | | | |--- feature_0 > 8.00
| | | | | | |--- class: 0
| | | |--- feature_4 > 0.50
| | | | |--- class: 0

BIN
src/tree/tree_model Normal file

Binary file not shown.