pod_Mikolaj

This commit is contained in:
MikeWMI 2020-06-09 15:59:02 +02:00
parent ecb0b8e426
commit d27aa09cd2
3 changed files with 285 additions and 0 deletions

209
data.csv Normal file
View File

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

59
decisiontree.py Normal file
View File

@ -0,0 +1,59 @@
import pandas as pd
#NIE AKTULAIZOWAĆ scikit / sklearn
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree.export import export_text
from sklearn.tree import export_graphviz
def decision(plant,feed,growth,dryness):
# czytanie pliku csv
df = pd.read_csv("C:\DATA\#Mike\#Studia\#Rok II- Semestr II\#Sztuczna_inteligencja\Projekt\AIProjekt\data.csv")
#print(df)
#zmiana słów na cyfry, ponieważ drzewo decyzyjne opiera się na cyfrach
z = {'CABBAGE': 2, 'PUMPKIN':4, 'CARROT':3, 'BEETROOT': 1}
df['PLANT'] = df['PLANT'].map(z)
d = {'NO': 0, 'YES': 1}
df['DEC'] = df['DEC'].map(d)
#print(df)
features_rest = ['PLANT','FEED','GROWTH','DRYNESS'] #dane, na których opiera się decyzja
features_dec = ['DEC'] #kolumna z decyją
X = df[features_rest]
y = df[features_dec]
#wyświetlkanie kolumn
#print(X)
#print(y)
#tworzenie drzewa
dtree = DecisionTreeClassifier()
#przypisanie danych
dtree = dtree.fit(X, y)
#eksport drzewa do tekstu
r = export_text(dtree, feature_names=features_rest)
#print("\nDrzewo decyzyjne\n")
#print(r)
a = dtree.predict([[plant,feed,growth,dryness]])
#return a
#print("\n[1] means FEED THE PLANT")
#print("[0] means NOT FEED THE PLANT\n")
print ("Decision for: ",plant,", feed: ", feed,", growth: ", growth,", dryness:", dryness," is ", a,"")
"""
plant = 1
feed = 35
growth = 20
#vermins = 0
dryness = 12
decision(plant,feed,growth,dryness)
"""

17
main.py
View File

@ -1,6 +1,7 @@
import pygame, sys import pygame, sys
from traktor import Traktor from traktor import Traktor
import dijkstra as di import dijkstra as di
import decisiontree as dt
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from tensorflow.keras.preprocessing import image from tensorflow.keras.preprocessing import image
@ -45,8 +46,10 @@ class Game(object):
#ładowanie tablicy ze zdjeciami #ładowanie tablicy ze zdjeciami
imgs = [] imgs = []
data_plant = []
img_dir = './imgs' img_dir = './imgs'
for _ in lokalizacje: for _ in lokalizacje:
data_plant.append([random.randrange(5, 90),random.randrange(0, 120),random.randrange(5, 90)])
imgs.append(img_dir + '/' + random.choice(os.listdir(img_dir))) imgs.append(img_dir + '/' + random.choice(os.listdir(img_dir)))
#model do rozpoznawania #model do rozpoznawania
@ -139,6 +142,20 @@ class Game(object):
#detektor roslin, 5 rezultatow #detektor roslin, 5 rezultatow
plt.imshow(img) plt.imshow(img)
preds = model.predict(x) preds = model.predict(x)
list_of_preds = preds.tolist()[0]
index = list_of_preds.index(max(list_of_preds))
#print(index)
if index == 0:
dt.decision(4, data_plant[pt][0],data_plant[pt][1],data_plant[pt][2])
if index == 1:
dt.decision(1, data_plant[pt][0],data_plant[pt][1],data_plant[pt][2])
if index == 2:
dt.decision(2, data_plant[pt][0],data_plant[pt][1],data_plant[pt][2])
if index == 3:
dt.decision(3, data_plant[pt][0],data_plant[pt][1],data_plant[pt][2])
print("kapusta, kalafior, grzyb, dynia\n {}\n".format(preds) ) print("kapusta, kalafior, grzyb, dynia\n {}\n".format(preds) )
plt.show() plt.show()