forked from s444426/AIProjekt
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
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,humidity,growth,dryness):
|
|
|
|
# czytanie pliku csv
|
|
df = pd.read_csv("./data.csv")
|
|
#print(df)
|
|
|
|
#zmiana słów na cyfry, ponieważ drzewo decyzyjne opiera się na cyfrach
|
|
z = {'CABBAGE': 2, 'PUMPKIN':4, 'MUSHROOM':3, 'CAULIFLOWER': 1}
|
|
df['PLANT'] = df['PLANT'].map(z)
|
|
|
|
d = {'NO': 0, 'YES': 1}
|
|
df['DEC'] = df['DEC'].map(d)
|
|
|
|
#print(df)
|
|
|
|
features_rest = ['PLANT','HUMIDITY','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,humidity,growth,dryness]])
|
|
#return a
|
|
#print("\n[1] means FEED THE PLANT")
|
|
#print("[0] means NOT FEED THE PLANT\n")
|
|
print ("Decision for: ",plant,", humidity: ", humidity,", growth: ", growth,", dryness:", dryness," is ", a,"\n")
|
|
|
|
|
|
|