2020-06-09 15:59:02 +02:00
|
|
|
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
|
2020-06-09 22:06:04 +02:00
|
|
|
df = pd.read_csv("data/data.csv")
|
2020-06-09 15:59:02 +02:00
|
|
|
#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)
|
|
|
|
"""
|
|
|
|
|
|
|
|
|