diff --git a/data.csv b/data.csv new file mode 100644 index 0000000..66a1b67 --- /dev/null +++ b/data.csv @@ -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 diff --git a/decisiontree.py b/decisiontree.py new file mode 100644 index 0000000..432eab3 --- /dev/null +++ b/decisiontree.py @@ -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) +""" + + diff --git a/main.py b/main.py index 1b6bf51..cb24afe 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import pygame, sys from traktor import Traktor import dijkstra as di +import decisiontree as dt import matplotlib.pyplot as plt from tensorflow.keras.preprocessing import image @@ -45,8 +46,10 @@ class Game(object): #ładowanie tablicy ze zdjeciami imgs = [] + data_plant = [] img_dir = './imgs' 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))) #model do rozpoznawania @@ -139,6 +142,20 @@ class Game(object): #detektor roslin, 5 rezultatow plt.imshow(img) 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) ) plt.show()