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ń
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, '%')
@ -146,10 +146,11 @@ def predict_data(data):
dict = queries.iloc[:, :-1].to_dict(orient="records")
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()
print("Planted: ", predicted_list[0][0])
return predicted_list[0][0]
def categorize_pH(pH):

View File

@ -1,71 +1,71 @@
header = ['previous', 'soil pH', 'dry level', 'label']
training_data = [
['carrot', 'alkaline', 'dry', 'beetroot'],
['carrot', 'slightly acidic', 'dry', 'beetroot'],
['cabbage', 'alkaline', 'dry', 'beetroot'],
['none', 'alkaline', 'dry', 'beetroot'],
['carrot', 'slightly acidic', 'medium wet', 'beetroot'],
['none', 'slightly acidic', 'dry', 'beetroot'],
['pumpkin', 'neutral', 'dry', 'beetroot'],
['beetroot', 'neutral', 'dry', 'beetroot'],
['cabbage', 'alkaline', 'medium wet', 'beetroot'],
['none', 'slightly acidic', 'medium wet', 'beetroot'],
['cabbage', 'acidic', 'dry', 'carrot'],
['none', 'acidic', 'medium wet', 'carrot'],
['carrot', 'neutral', 'dry', 'carrot'],
['beetroot', 'slightly acidic', 'dry', 'carrot'],
['pumpkin', 'acidic', 'medium wet', 'carrot'],
['beetroot', 'acidic', 'medium wet', 'carrot'],
['carrot', 'neutral', 'dry', 'carrot'],
['pumpkin', 'slightly acidic', 'medium wet', 'carrot'],
['beetroot', 'neutral', 'wet', 'pumpkin'],
['mushroom', 'alkaline', 'dry', 'cauliflower'],
['mushroom', 'slightly acidic', 'dry', 'cauliflower'],
['cabbage', 'alkaline', 'dry', 'cauliflower'],
['none', 'alkaline', 'dry', 'cauliflower'],
['mushroom', 'slightly acidic', 'medium wet', 'cauliflower'],
['none', 'slightly acidic', 'dry', 'cauliflower'],
['pumpkin', 'neutral', 'dry', 'cauliflower'],
['cauliflower', 'neutral', 'dry', 'cauliflower'],
['cabbage', 'alkaline', 'medium wet', 'cauliflower'],
['none', 'slightly acidic', 'medium wet', 'cauliflower'],
['cabbage', 'acidic', 'dry', 'mushroom'],
['none', 'acidic', 'medium wet', 'mushroom'],
['mushroom', 'neutral', 'dry', 'mushroom'],
['cauliflower', 'slightly acidic', 'dry', 'mushroom'],
['pumpkin', 'acidic', 'medium wet', 'mushroom'],
['cauliflower', 'acidic', 'medium wet', 'mushroom'],
['mushroom', 'neutral', 'dry', 'mushroom'],
['pumpkin', 'slightly acidic', 'medium wet', 'mushroom'],
['cauliflower', 'neutral', 'wet', 'pumpkin'],
['none', 'neutral', 'wet', 'pumpkin'],
['carrot', 'slightly acidic', 'wet', 'pumpkin'],
['mushroom', 'slightly acidic', 'wet', 'pumpkin'],
['pumpkin', 'neutral', 'wet', 'pumpkin'],
['cabbage', 'slightly acidic', 'medium wet', 'pumpkin'],
['carrot', 'neutral', 'wet', 'pumpkin'],
['mushroom', 'neutral', 'wet', 'pumpkin'],
['cabbage', 'neutral', 'wet', 'pumpkin'],
['none', 'slightly acidic', 'wet', 'pumpkin'],
['beetroot', 'slightly acidic', 'medium wet', 'pumpkin'],
['carrot', 'neutral', 'medium wet', 'cabbage'],
['cauliflower', 'slightly acidic', 'medium wet', 'pumpkin'],
['mushroom', 'neutral', 'medium wet', 'cabbage'],
['pumpkin', 'alkaline', 'wet', 'cabbage'],
['none', 'alkaline', 'medium wet', 'cabbage'],
['beetroot', 'neutral', 'medium wet', 'cabbage'],
['cauliflower', 'neutral', 'medium wet', 'cabbage'],
['cabbage', 'slightly acidic', 'wet', 'cabbage'],
['none', 'neutral', 'medium wet', 'cabbage'],
['cabbage', 'neutral', 'medium wet', 'cabbage'],
['carrot', 'alkaline', 'wet', 'cabbage'],
['mushroom', 'alkaline', 'wet', 'cabbage'],
['none', 'alkaline', 'wet', 'cabbage'],
['pumpkin', 'neutral', 'medium wet', 'cabbage'],
['carrot', 'neutral', 'soaking wet', 'none'],
['beetroot', 'alkaline', 'very dry', 'none'],
['mushroom', 'neutral', 'soaking wet', 'none'],
['cauliflower', 'alkaline', 'very dry', 'none'],
['none', 'alkaline', 'soaking wet', 'none'],
['cabbage', 'acidic', 'medium wet', 'none'],
['pumpkin', 'acidic', 'soaking wet', 'none'],
['cabbage', 'slightly acidic', 'soaking wet', 'none'],
['none', 'slightly acidic', 'soaking wet', 'none'],
['carrot', 'neutral', 'very dry', 'none'],
['carrot', 'acidic', 'medium wet', 'none'],
['mushroom', 'neutral', 'very dry', 'none'],
['mushroom', 'acidic', 'medium wet', 'none'],
['pumpkin', 'neutral', 'soaking wet', 'none']
]
testing_data = [
['beetroot', 'neutral', 'dry', 'beetroot'],
['cabbage', 'alkaline', 'medium wet', 'beetroot'],
['none', 'slightly acidic', 'medium wet', 'beetroot'],
['cabbage', 'acidic', 'dry', 'carrot'],
['none', 'acidic', 'medium wet', 'carrot'],
['carrot', 'neutral', 'dry', 'carrot'],
['beetroot', 'neutral', 'wet', 'pumpkin'],
['cauliflower', 'neutral', 'dry', 'cauliflower'],
['cabbage', 'alkaline', 'medium wet', 'cauliflower'],
['none', 'slightly acidic', 'medium wet', 'cauliflower'],
['cabbage', 'acidic', 'dry', 'mushroom'],
['none', 'acidic', 'medium wet', 'mushroom'],
['mushroom', 'neutral', 'dry', 'mushroom'],
['cauliflower', 'neutral', 'wet', 'pumpkin'],
['none', 'neutral', 'wet', 'pumpkin'],
['carrot', 'slightly acidic', 'wet', 'pumpkin'],
['carrot', 'neutral', 'medium wet', 'cabbage'],
['mushroom', 'slightly acidic', 'wet', 'pumpkin'],
['mushroom', 'neutral', 'medium wet', 'cabbage'],
['pumpkin', 'alkaline', 'wet', 'cabbage'],
['none', 'alkaline', 'medium wet', 'cabbage'],
['carrot', 'neutral', 'soaking wet', 'none'],
['beetroot', 'alkaline', 'very dry', 'none'],
['mushroom', 'neutral', 'soaking wet', 'none'],
['cauliflower', 'alkaline', 'very dry', '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))
#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%
if(data_plant[pt][1] > 90):
predict_data([names[index], data_soil[pt][0], data_soil[pt][1]])
index = names.index(names[index])
#imgs[pt] = img_dir + '/' + names[index] + '.jpg'
data_plant[pt] = [0, 0, 50]
new_plant = predict_data([names[index], data_soil[pt][0], data_soil[pt][1]])
if(new_plant != 'none'):
index = names.index(new_plant)
imgs[pt] = img_dir + '/' + (os.listdir(img_dir))[index]
data_plant[pt] = [0, 0, 50]
else:
print("Planted: none")
@ -169,9 +174,6 @@ class Game(object):
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()
def krata(self):
#wymiary