This commit is contained in:
s444426 2020-06-09 20:08:06 +02:00
parent 2bae8269f2
commit c7ebf5b1b7
3 changed files with 53 additions and 50 deletions

5
ID3.py
View File

@ -127,7 +127,7 @@ def test(data, tree):
# Obliczenie precyzji przewidywań # Obliczenie precyzji przewidywań
for i in range(len(data)): for i in range(len(data)):
predicted.loc[i, "predicted"] = predict(queries[i], tree, 'beetroot') predicted.loc[i, "predicted"] = predict(queries[i], tree, 'mushroom')
print('Precyzja przewidywań: ', (np.sum(predicted["predicted"] == data["label"]) / len(data)) * 100, '%') print('Precyzja przewidywań: ', (np.sum(predicted["predicted"] == data["label"]) / len(data)) * 100, '%')
@ -146,10 +146,11 @@ def predict_data(data):
dict = queries.iloc[:, :-1].to_dict(orient="records") dict = queries.iloc[:, :-1].to_dict(orient="records")
for i in range(len(parse_data)): for i in range(len(parse_data)):
predicted.loc[i, "predicted"] = predict(dict[i], tree, 'beetroot') predicted.loc[i, "predicted"] = predict(dict[i], tree, 'mushroom')
predicted_list = predicted.values.tolist() predicted_list = predicted.values.tolist()
print("Planted: ", predicted_list[0][0]) print("Planted: ", predicted_list[0][0])
return predicted_list[0][0]
def categorize_pH(pH): def categorize_pH(pH):

View File

@ -1,71 +1,71 @@
header = ['previous', 'soil pH', 'dry level', 'label'] header = ['previous', 'soil pH', 'dry level', 'label']
training_data = [ training_data = [
['carrot', 'alkaline', 'dry', 'beetroot'], ['mushroom', 'alkaline', 'dry', 'cauliflower'],
['carrot', 'slightly acidic', 'dry', 'beetroot'], ['mushroom', 'slightly acidic', 'dry', 'cauliflower'],
['cabbage', 'alkaline', 'dry', 'beetroot'], ['cabbage', 'alkaline', 'dry', 'cauliflower'],
['none', 'alkaline', 'dry', 'beetroot'], ['none', 'alkaline', 'dry', 'cauliflower'],
['carrot', 'slightly acidic', 'medium wet', 'beetroot'], ['mushroom', 'slightly acidic', 'medium wet', 'cauliflower'],
['none', 'slightly acidic', 'dry', 'beetroot'], ['none', 'slightly acidic', 'dry', 'cauliflower'],
['pumpkin', 'neutral', 'dry', 'beetroot'], ['pumpkin', 'neutral', 'dry', 'cauliflower'],
['beetroot', 'neutral', 'dry', 'beetroot'], ['cauliflower', 'neutral', 'dry', 'cauliflower'],
['cabbage', 'alkaline', 'medium wet', 'beetroot'], ['cabbage', 'alkaline', 'medium wet', 'cauliflower'],
['none', 'slightly acidic', 'medium wet', 'beetroot'], ['none', 'slightly acidic', 'medium wet', 'cauliflower'],
['cabbage', 'acidic', 'dry', 'carrot'], ['cabbage', 'acidic', 'dry', 'mushroom'],
['none', 'acidic', 'medium wet', 'carrot'], ['none', 'acidic', 'medium wet', 'mushroom'],
['carrot', 'neutral', 'dry', 'carrot'], ['mushroom', 'neutral', 'dry', 'mushroom'],
['beetroot', 'slightly acidic', 'dry', 'carrot'], ['cauliflower', 'slightly acidic', 'dry', 'mushroom'],
['pumpkin', 'acidic', 'medium wet', 'carrot'], ['pumpkin', 'acidic', 'medium wet', 'mushroom'],
['beetroot', 'acidic', 'medium wet', 'carrot'], ['cauliflower', 'acidic', 'medium wet', 'mushroom'],
['carrot', 'neutral', 'dry', 'carrot'], ['mushroom', 'neutral', 'dry', 'mushroom'],
['pumpkin', 'slightly acidic', 'medium wet', 'carrot'], ['pumpkin', 'slightly acidic', 'medium wet', 'mushroom'],
['beetroot', 'neutral', 'wet', 'pumpkin'], ['cauliflower', 'neutral', 'wet', 'pumpkin'],
['none', 'neutral', 'wet', 'pumpkin'], ['none', 'neutral', 'wet', 'pumpkin'],
['carrot', 'slightly acidic', 'wet', 'pumpkin'], ['mushroom', 'slightly acidic', 'wet', 'pumpkin'],
['pumpkin', 'neutral', 'wet', 'pumpkin'], ['pumpkin', 'neutral', 'wet', 'pumpkin'],
['cabbage', 'slightly acidic', 'medium wet', 'pumpkin'], ['cabbage', 'slightly acidic', 'medium wet', 'pumpkin'],
['carrot', 'neutral', 'wet', 'pumpkin'], ['mushroom', 'neutral', 'wet', 'pumpkin'],
['cabbage', 'neutral', 'wet', 'pumpkin'], ['cabbage', 'neutral', 'wet', 'pumpkin'],
['none', 'slightly acidic', 'wet', 'pumpkin'], ['none', 'slightly acidic', 'wet', 'pumpkin'],
['beetroot', 'slightly acidic', 'medium wet', 'pumpkin'], ['cauliflower', 'slightly acidic', 'medium wet', 'pumpkin'],
['carrot', 'neutral', 'medium wet', 'cabbage'], ['mushroom', 'neutral', 'medium wet', 'cabbage'],
['pumpkin', 'alkaline', 'wet', 'cabbage'], ['pumpkin', 'alkaline', 'wet', 'cabbage'],
['none', 'alkaline', 'medium wet', 'cabbage'], ['none', 'alkaline', 'medium wet', 'cabbage'],
['beetroot', 'neutral', 'medium wet', 'cabbage'], ['cauliflower', 'neutral', 'medium wet', 'cabbage'],
['cabbage', 'slightly acidic', 'wet', 'cabbage'], ['cabbage', 'slightly acidic', 'wet', 'cabbage'],
['none', 'neutral', 'medium wet', 'cabbage'], ['none', 'neutral', 'medium wet', 'cabbage'],
['cabbage', 'neutral', 'medium wet', 'cabbage'], ['cabbage', 'neutral', 'medium wet', 'cabbage'],
['carrot', 'alkaline', 'wet', 'cabbage'], ['mushroom', 'alkaline', 'wet', 'cabbage'],
['none', 'alkaline', 'wet', 'cabbage'], ['none', 'alkaline', 'wet', 'cabbage'],
['pumpkin', 'neutral', 'medium wet', 'cabbage'], ['pumpkin', 'neutral', 'medium wet', 'cabbage'],
['carrot', 'neutral', 'soaking wet', 'none'], ['mushroom', 'neutral', 'soaking wet', 'none'],
['beetroot', 'alkaline', 'very dry', 'none'], ['cauliflower', 'alkaline', 'very dry', 'none'],
['none', 'alkaline', 'soaking wet', 'none'], ['none', 'alkaline', 'soaking wet', 'none'],
['cabbage', 'acidic', 'medium wet', 'none'], ['cabbage', 'acidic', 'medium wet', 'none'],
['pumpkin', 'acidic', 'soaking wet', 'none'], ['pumpkin', 'acidic', 'soaking wet', 'none'],
['cabbage', 'slightly acidic', 'soaking wet', 'none'], ['cabbage', 'slightly acidic', 'soaking wet', 'none'],
['none', 'slightly acidic', 'soaking wet', 'none'], ['none', 'slightly acidic', 'soaking wet', 'none'],
['carrot', 'neutral', 'very dry', 'none'], ['mushroom', 'neutral', 'very dry', 'none'],
['carrot', 'acidic', 'medium wet', 'none'], ['mushroom', 'acidic', 'medium wet', 'none'],
['pumpkin', 'neutral', 'soaking wet', 'none'] ['pumpkin', 'neutral', 'soaking wet', 'none']
] ]
testing_data = [ testing_data = [
['beetroot', 'neutral', 'dry', 'beetroot'], ['cauliflower', 'neutral', 'dry', 'cauliflower'],
['cabbage', 'alkaline', 'medium wet', 'beetroot'], ['cabbage', 'alkaline', 'medium wet', 'cauliflower'],
['none', 'slightly acidic', 'medium wet', 'beetroot'], ['none', 'slightly acidic', 'medium wet', 'cauliflower'],
['cabbage', 'acidic', 'dry', 'carrot'], ['cabbage', 'acidic', 'dry', 'mushroom'],
['none', 'acidic', 'medium wet', 'carrot'], ['none', 'acidic', 'medium wet', 'mushroom'],
['carrot', 'neutral', 'dry', 'carrot'], ['mushroom', 'neutral', 'dry', 'mushroom'],
['beetroot', 'neutral', 'wet', 'pumpkin'], ['cauliflower', 'neutral', 'wet', 'pumpkin'],
['none', 'neutral', 'wet', 'pumpkin'], ['none', 'neutral', 'wet', 'pumpkin'],
['carrot', 'slightly acidic', 'wet', 'pumpkin'], ['mushroom', 'slightly acidic', 'wet', 'pumpkin'],
['carrot', 'neutral', 'medium wet', 'cabbage'], ['mushroom', 'neutral', 'medium wet', 'cabbage'],
['pumpkin', 'alkaline', 'wet', 'cabbage'], ['pumpkin', 'alkaline', 'wet', 'cabbage'],
['none', 'alkaline', 'medium wet', 'cabbage'], ['none', 'alkaline', 'medium wet', 'cabbage'],
['carrot', 'neutral', 'soaking wet', 'none'], ['mushroom', 'neutral', 'soaking wet', 'none'],
['beetroot', 'alkaline', 'very dry', 'none'], ['cauliflower', 'alkaline', 'very dry', 'none'],
['none', 'alkaline', 'soaking wet', 'none'], ['none', 'alkaline', 'soaking wet', 'none'],
] ]

18
main.py
View File

@ -149,14 +149,19 @@ class Game(object):
index = list_of_preds.index(max(list_of_preds)) index = list_of_preds.index(max(list_of_preds))
#print(index) #print(index)
names = ['cabbage', 'beetroot', 'carrot', 'pumpkin'] print("kapusta, kalafior, grzyb, dynia\n {}\n".format(preds) )
plt.show()
names = ['cabbage', 'cauliflower', 'mushroom', 'pumpkin']
# decyzja o posadzeniu nowej rośliny następuje wtedy, gdy jest ona dojrzała przynajmniej w 90% # decyzja o posadzeniu nowej rośliny następuje wtedy, gdy jest ona dojrzała przynajmniej w 90%
if(data_plant[pt][1] > 90): if(data_plant[pt][1] > 90):
predict_data([names[index], data_soil[pt][0], data_soil[pt][1]])
index = names.index(names[index]) new_plant = predict_data([names[index], data_soil[pt][0], data_soil[pt][1]])
#imgs[pt] = img_dir + '/' + names[index] + '.jpg' if(new_plant != 'none'):
data_plant[pt] = [0, 0, 50] index = names.index(new_plant)
imgs[pt] = img_dir + '/' + (os.listdir(img_dir))[index]
data_plant[pt] = [0, 0, 50]
else: else:
print("Planted: none") print("Planted: none")
@ -168,9 +173,6 @@ class Game(object):
dt.decision(2, data_plant[pt][0],data_plant[pt][1],data_plant[pt][2]) dt.decision(2, data_plant[pt][0],data_plant[pt][1],data_plant[pt][2])
if index == 3: if index == 3:
dt.decision(3, data_plant[pt][0],data_plant[pt][1],data_plant[pt][2]) 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()
def krata(self): def krata(self):