Merge pull request 'complete decision tree' (#23) from d_tree into main

Reviewed-on: #23
Reviewed-by: Tim Barvenov <timbar@st.amu.edu.pl>
This commit is contained in:
Tim Barvenov 2023-05-19 17:51:03 +02:00
commit 3fe4b6f2e1
31 changed files with 1286 additions and 1105 deletions

View File

@ -1,22 +1,200 @@
1-2-3-4-5;1-green 2-yellow 3-orange 4-black 5-while 6-blue;in dB 0-100;0-24;0/1;in cm;in C;0/1
Size;Color;Sound;Time;Smell;Height;Temperature;ToRemove
1;2;0;16;1;10;25;1
2;1;0;12;0;50;24;0
2;3;30;13;1;38;38;0
1;4;0;7;1;5;27;1
1;2;0;16;1;10;25;1
2;1;0;12;0;50;24;0
2;3;30;13;1;38;38;0
1;4;0;7;1;5;27;1
1;2;0;16;1;10;25;1
2;1;0;12;0;50;24;0
2;3;30;13;1;38;38;0
1;4;0;7;1;5;27;1
1;2;0;16;1;10;25;1
2;1;0;12;0;50;24;0
2;3;30;13;1;38;38;0
1;4;0;7;1;5;27;1
1;2;0;16;1;10;25;1
2;1;0;12;0;50;24;0
2;3;30;13;1;38;38;0
1;4;0;7;1;5;27;1
1 2 3 4 5;1 2 3 4 5 6 7 8 9;in db 0-100;0/1;0/1;in cm;in C;0-7;0/1
Size;Color;Sound;Sharp;Smell;Length;Temperature;Weight;ToRemove
1;1;0;0;0;2;22;0;1
1;2;0;0;0;2;22;0;1
1;3;0;0;0;2;22;0;1
1;4;0;0;0;2;22;0;1
1;5;0;0;0;2;22;0;1
1;6;0;0;0;2;22;0;1
1;7;0;0;0;2;22;0;1
1;8;0;0;0;2;22;0;1
1;9;0;0;0;2;22;0;1
1;2;0;0;1;3;25;0;1
1;2;0;0;1;4;25;0;1
1;2;0;0;1;5;25;0;1
2;2;0;0;1;3;25;0;1
2;2;0;0;1;4;25;0;1
2;2;0;0;1;5;25;0;1
2;2;0;0;1;6;25;0;1
3;2;0;0;1;3;25;0;1
1;7;0;0;1;3;25;2;1
1;6;0;0;1;4;25;2;1
1;6;0;0;1;5;25;2;1
1;6;0;0;1;2;25;2;1
2;6;0;0;1;2;25;3;1
2;6;0;0;1;3;25;3;1
2;6;0;0;1;4;25;3;1
2;6;0;0;1;5;25;3;1
3;6;0;0;1;2;25;4;1
2;1;0;0;0;20;24;1;0
2;2;0;0;0;20;24;1;0
2;3;0;0;0;20;24;1;0
2;4;0;0;0;20;24;1;0
2;5;0;0;0;20;24;1;0
2;6;0;0;0;20;24;1;0
2;7;0;0;0;20;24;1;0
2;8;0;0;0;20;24;1;0
2;9;0;0;0;20;24;1;0
1;1;0;1;0;1;20;0;0
1;2;0;1;0;1;20;0;0
1;3;0;1;0;1;20;0;0
1;4;0;1;0;1;20;0;0
1;5;0;1;0;1;20;0;0
1;6;0;1;0;1;20;0;0
1;7;0;1;0;1;20;0;0
1;8;0;1;0;1;20;0;0
2;4;0;0;0;14;22;1;0
1;2;0;0;1;6;24;1;1
2;2;0;0;1;6;24;1;1
1;2;0;0;1;5;24;1;1
3;1;4;0;0;18;24;2;0
3;2;4;0;0;18;24;2;0
3;3;4;0;0;18;24;2;0
3;4;4;0;0;18;24;2;0
3;5;4;0;0;18;24;2;0
3;6;4;0;0;18;24;2;0
3;7;4;0;0;18;24;2;0
3;8;4;0;0;18;24;2;0
3;9;4;0;0;18;24;2;0
4;3;20;0;1;32;37;5;0
4;4;20;0;1;32;37;5;0
4;5;20;0;1;32;37;5;0
4;6;20;0;1;32;37;5;0
5;3;25;0;1;40;37;6;0
5;4;25;0;1;40;37;6;0
5;5;25;0;1;40;37;6;0
5;6;25;0;1;40;37;6;0
1;5;0;0;0;20;22;2;0
1;5;0;0;0;30;22;2;0
1;5;0;0;0;40;22;2;0
1;5;0;0;0;50;22;2;0
1;4;0;0;0;20;22;2;0
1;4;0;0;0;30;22;2;0
1;4;0;0;0;40;22;2;0
1;4;0;0;0;50;22;2;0
2;5;0;0;0;20;22;2;0
2;5;0;0;0;30;22;2;0
2;5;0;0;0;40;22;2;0
2;4;0;0;0;20;22;2;0
2;4;0;0;0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;0;0;25;22;2;0
3;3;0;0;0;25;22;2;0
3;4;0;0;0;25;22;2;0
3;5;0;0;0;25;22;2;0
3;6;0;0;0;25;22;2;0
3;7;0;0;0;25;22;2;0
3;8;0;0;0;25;22;2;0
3;9;0;0;0;25;22;2;0

1 1-2-3-4-5 1 2 3 4 5 1-green 2-yellow 3-orange 4-black 5-while 6-blue 1 2 3 4 5 6 7 8 9 in dB 0-100 in db 0-100 0-24 0/1 0/1 in cm in C 0-7 0/1
2 Size Size Color Color Sound Sound Time Smell Sharp ToRemove Smell Height Length Temperature Weight ToRemove
3 1 1 2 1 0 0 16 1 0 1 0 10 2 25 22 0 1
4 2 1 1 2 0 0 12 0 0 50 2 24 22 0 1
5 2 1 3 3 30 0 13 1 0 0 38 2 38 22 0 1
6 1 1 4 4 0 0 7 1 0 1 0 5 2 27 22 0 1
7 1 1 2 5 0 0 16 1 0 1 0 10 2 25 22 0 1
8 2 1 1 6 0 0 12 0 0 50 2 24 22 0 1
9 2 1 3 7 30 0 13 1 0 0 38 2 38 22 0 1
10 1 1 4 8 0 0 7 1 0 1 0 5 2 27 22 0 1
11 1 1 2 9 0 0 16 1 0 1 0 10 2 25 22 0 1
12 2 1 1 2 0 0 12 0 0 1 50 3 24 25 0 1
13 2 1 3 2 30 0 13 1 0 0 1 38 4 38 25 0 1
14 1 1 4 2 0 0 7 1 0 1 5 27 25 0 1
15 1 2 2 2 0 0 16 1 0 1 10 3 25 0 1
16 2 2 1 2 0 0 12 0 0 1 50 4 24 25 0 1
17 2 2 3 2 30 0 13 1 0 0 1 38 5 38 25 0 1
18 1 2 4 2 0 0 7 1 0 1 5 6 27 25 0 1
19 1 3 2 2 0 0 16 1 0 1 10 3 25 0 1
20 2 1 1 7 0 0 12 0 0 1 50 3 24 25 2 1
21 2 1 3 6 30 0 13 1 0 0 1 38 4 38 25 2 1
22 1 1 4 6 0 0 7 1 0 1 5 27 25 2 1
23 1 6 0 0 1 2 25 2 1
24 2 6 0 0 1 2 25 3 1
25 2 6 0 0 1 3 25 3 1
26 2 6 0 0 1 4 25 3 1
27 2 6 0 0 1 5 25 3 1
28 3 6 0 0 1 2 25 4 1
29 2 1 0 0 0 20 24 1 0
30 2 2 0 0 0 20 24 1 0
31 2 3 0 0 0 20 24 1 0
32 2 4 0 0 0 20 24 1 0
33 2 5 0 0 0 20 24 1 0
34 2 6 0 0 0 20 24 1 0
35 2 7 0 0 0 20 24 1 0
36 2 8 0 0 0 20 24 1 0
37 2 9 0 0 0 20 24 1 0
38 1 1 0 1 0 1 20 0 0
39 1 2 0 1 0 1 20 0 0
40 1 3 0 1 0 1 20 0 0
41 1 4 0 1 0 1 20 0 0
42 1 5 0 1 0 1 20 0 0
43 1 6 0 1 0 1 20 0 0
44 1 7 0 1 0 1 20 0 0
45 1 8 0 1 0 1 20 0 0
46 2 4 0 0 0 14 22 1 0
47 1 2 0 0 1 6 24 1 1
48 2 2 0 0 1 6 24 1 1
49 1 2 0 0 1 5 24 1 1
50 3 1 4 0 0 18 24 2 0
51 3 2 4 0 0 18 24 2 0
52 3 3 4 0 0 18 24 2 0
53 3 4 4 0 0 18 24 2 0
54 3 5 4 0 0 18 24 2 0
55 3 6 4 0 0 18 24 2 0
56 3 7 4 0 0 18 24 2 0
57 3 8 4 0 0 18 24 2 0
58 3 9 4 0 0 18 24 2 0
59 4 3 20 0 1 32 37 5 0
60 4 4 20 0 1 32 37 5 0
61 4 5 20 0 1 32 37 5 0
62 4 6 20 0 1 32 37 5 0
63 5 3 25 0 1 40 37 6 0
64 5 4 25 0 1 40 37 6 0
65 5 5 25 0 1 40 37 6 0
66 5 6 25 0 1 40 37 6 0
67 1 5 0 0 0 20 22 2 0
68 1 5 0 0 0 30 22 2 0
69 1 5 0 0 0 40 22 2 0
70 1 5 0 0 0 50 22 2 0
71 1 4 0 0 0 20 22 2 0
72 1 4 0 0 0 30 22 2 0
73 1 4 0 0 0 40 22 2 0
74 1 4 0 0 0 50 22 2 0
75 2 5 0 0 0 20 22 2 0
76 2 5 0 0 0 30 22 2 0
77 2 5 0 0 0 40 22 2 0
78 2 4 0 0 0 20 22 2 0
79 2 4 0 0 0 30 22 2 0
80 2 4 0 0 0 40 22 2 0
81 1 5 0 0 1 2 24 0 1
82 1 3 0 0 0 13 23 0 1
83 1 4 0 0 0 13 23 0 1
84 1 5 0 0 0 13 23 0 1
85 1 6 0 0 0 13 23 0 1
86 1 3 0 0 0 14 23 0 1
87 1 4 0 0 0 14 23 0 1
88 1 5 0 0 0 14 23 0 1
89 1 6 0 0 0 14 23 0 1
90 1 3 0 0 0 15 23 0 1
91 1 4 0 0 0 15 23 0 1
92 1 5 0 0 0 15 23 0 1
93 1 6 0 0 0 15 23 0 1
94 1 1 0 1 0 3 22 1 1
95 1 2 0 1 0 3 22 1 1
96 1 3 0 1 0 3 22 1 1
97 1 4 0 1 0 3 22 1 1
98 1 5 0 1 0 3 22 1 1
99 1 6 0 1 0 3 22 1 1
100 1 7 0 1 0 3 22 1 1
101 1 8 0 1 0 3 22 1 1
102 1 9 0 1 0 3 22 1 1
103 2 1 0 1 0 7 22 1 0
104 2 2 0 1 0 7 22 1 0
105 2 3 0 1 0 7 22 1 0
106 2 4 0 1 0 7 22 1 0
107 2 5 0 1 0 7 22 1 0
108 2 6 0 1 0 7 22 1 0
109 2 7 0 1 0 7 22 1 0
110 2 8 0 1 0 7 22 1 0
111 2 9 0 1 0 7 22 1 0
112 3 3 10 0 1 24 36 3 0
113 3 4 10 0 1 24 36 3 0
114 3 5 10 0 1 24 36 3 0
115 3 6 10 0 1 24 36 3 0
116 1 1 0 0 0 2 20 1 0
117 1 2 0 0 0 2 20 1 0
118 1 3 0 0 0 2 20 1 0
119 1 4 0 0 0 2 20 1 0
120 1 5 0 0 0 2 20 1 0
121 1 6 0 0 0 2 20 1 0
122 1 7 0 0 0 2 20 1 0
123 1 8 0 0 0 2 20 1 0
124 1 9 0 0 0 2 20 1 0
125 2 1 0 0 1 2 24 0 1
126 2 2 0 0 1 2 24 0 1
127 2 3 0 0 1 2 24 0 1
128 2 7 0 0 1 2 24 0 1
129 2 8 0 0 1 2 24 0 1
130 2 9 0 0 1 2 24 0 1
131 1 5 0 0 0 2 22 0 1
132 1 5 0 0 0 3 22 0 1
133 1 5 0 0 0 4 22 0 1
134 1 6 0 0 0 2 22 0 1
135 1 6 0 0 0 3 22 0 1
136 1 6 0 0 0 4 22 0 1
137 2 5 0 0 0 2 22 0 1
138 2 5 0 0 0 3 22 0 1
139 2 5 0 0 0 4 22 0 1
140 2 6 0 0 0 2 22 0 1
141 2 6 0 0 0 3 22 0 1
142 2 6 0 0 0 4 22 0 1
143 2 1 0 0 0 2 20 0 0
144 2 2 0 0 0 2 20 0 0
145 2 3 0 0 0 2 20 0 0
146 2 4 0 0 0 2 20 0 0
147 2 5 0 0 0 2 20 0 0
148 2 6 0 0 0 2 20 0 0
149 2 7 0 0 0 2 20 0 0
150 2 8 0 0 0 2 20 0 0
151 2 9 0 0 0 2 20 0 0
152 2 1 0 0 1 3 22 0 1
153 2 2 0 0 1 3 22 0 1
154 2 3 0 0 1 3 22 0 1
155 2 4 0 0 1 3 22 0 1
156 2 5 0 0 1 3 22 0 1
157 2 6 0 0 1 3 22 0 1
158 2 7 0 0 1 3 22 0 1
159 2 8 0 0 1 3 22 0 1
160 2 9 0 0 1 3 22 0 1
161 3 1 0 0 0 16 23 3 0
162 3 2 0 0 0 16 23 3 0
163 3 3 0 0 0 16 23 3 0
164 3 4 0 0 0 16 23 3 0
165 3 5 0 0 0 16 23 3 0
166 3 6 0 0 0 16 23 3 0
167 3 7 0 0 0 16 23 3 0
168 3 8 0 0 0 16 23 3 0
169 3 9 0 0 0 16 23 3 0
170 1 5 0 0 0 2 23 0 1
171 1 5 0 0 0 3 23 0 1
172 1 5 0 0 0 4 23 0 1
173 1 5 0 0 0 5 23 0 1
174 1 5 0 0 0 6 23 0 1
175 2 5 0 0 0 3 23 0 1
176 2 5 0 0 0 4 23 0 1
177 2 5 0 0 0 5 23 0 1
178 2 5 0 0 0 6 23 0 1
179 2 5 0 0 0 2 23 0 1
180 2 5 0 0 1 4 26 1 1
181 3 5 0 0 1 4 26 2 1
182 1 7 0 1 0 1 22 0 1
183 1 7 0 1 0 1 22 0 1
184 4 1 0 0 1 30 21 4 0
185 4 1 0 0 1 25 21 4 0
186 1 6 0 0 1 1 22 0 1
187 1 6 0 0 1 1 22 1 1
188 4 3 30 0 1 50 36 4 0
189 5 3 30 0 1 50 36 4 0
190 1 1 0 0 0 9 22 0 0
191 1 8 0 0 0 9 22 0 0
192 3 1 0 0 0 25 22 2 0
193 3 2 0 0 0 25 22 2 0
194 3 3 0 0 0 25 22 2 0
195 3 4 0 0 0 25 22 2 0
196 3 5 0 0 0 25 22 2 0
197 3 6 0 0 0 25 22 2 0
198 3 7 0 0 0 25 22 2 0
199 3 8 0 0 0 25 22 2 0
200 3 9 0 0 0 25 22 2 0

Binary file not shown.

View File

@ -6,13 +6,13 @@ import joblib
pima = pd.read_csv("data.csv", header=1, delimiter=';')
feature_cols = ['Size', 'Color', 'Sound', 'Time','Smell', 'Height','Temperature']
feature_cols = ['Size', 'Color', 'Sound', 'Sharp','Smell', 'Length','Temperature', 'Weight']
X = pima[feature_cols]
y = pima.ToRemove
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
clf = DecisionTreeClassifier()
clf = clf.fit(X_train,y_train)
clf = clf.fit(X_train.values, y_train)
joblib.dump(clf, 'decision_tree_model.pkl')

View File

@ -21,10 +21,12 @@ class VacuumMoveCommand(Command):
if not self.world.accepted_move(end_x, end_y):
return
if self.world.is_garbage_at(end_x, end_y):
if self.vacuum.get_container_filling() < 100:
tmp = self.world.is_garbage_at(end_x, end_y)
if len(tmp) > 0:
for t in tmp:
if self.vacuum.get_container_filling() < 1000:
self.vacuum.increase_container_filling()
self.world.dust[end_x][end_y].pop()
self.world.dust[end_x][end_y].remove(t)
if self.world.is_docking_station_at(end_x, end_y):
self.vacuum.dump_trash()

View File

@ -14,4 +14,4 @@ class Cat(Entity):
self.sleeping = False
self.direction = 0
self.props = [1,2,0,16,1,10,25]
self.props = [4,2,20,0,1,32,37,5]

View File

@ -5,4 +5,4 @@ from domain.world import World
class Earring(Entity):
def __init__(self, x: int, y: int):
super().__init__(x, y, "EARRING")
self.props = [2,1,0,12,0,50,24]
self.props = [1,9,0,1,0,1,20,0]

View File

@ -6,6 +6,6 @@ class Garbage(Entity):
super().__init__(x, y, "PEEL")
self.wet = False
self.size = 0
self.props = [1,2,0,16,1,10,25]
self.props = [2,2,0,0,1,4,24,1]
# TODO GARBAGE: add more properties

View File

@ -32,11 +32,10 @@ class World:
def is_obstacle_at(self, x: int, y: int) -> bool:
return bool(self.obstacles[x][y])
def is_garbage_at(self, x: int, y: int) -> bool:
def is_garbage_at(self, x: int, y: int):
if len(self.dust[x][y]) == 0:
return False
tmp = evaluate([self.dust[x][y][0].props])
return bool(tmp[0])
return []
return [i for i in self.dust[x][y] if evaluate([i.props])[0] == 1]
def is_docking_station_at(self, x: int, y: int) -> bool:
return bool(self.doc_station.x == x and self.doc_station.y == y)

View File

@ -150,7 +150,9 @@ def generate_world(tiles_x: int, tiles_y: int) -> World:
world.add_entity(Entity(3, 4, "PLANT2"))
world.add_entity(Entity(8, 8, "PLANT2"))
world.add_entity(Entity(9, 3, "PLANT3"))
world.add_entity(Earring(9, 7))
world.add_entity(Earring(5, 5))
world.add_entity(Earring(4, 6))
for x in range(world.width):