labes-correction
This commit is contained in:
parent
04612d5cf3
commit
cf80f84132
209
data.csv
Normal file
209
data.csv
Normal file
@ -0,0 +1,209 @@
|
||||
PLANT,HUMIDITY,GROWTH,DRYNESS,DEC
|
||||
CAULIFLOWER,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
|
||||
CAULIFLOWER,23,99,30,NO
|
||||
MUSHROOM,53,94,30,NO
|
||||
CAULIFLOWER,28,120,31,NO
|
||||
MUSHROOM,29,91,34,NO
|
||||
CAULIFLOWER,34,121,34,NO
|
||||
CAULIFLOWER,33,110,36,NO
|
||||
MUSHROOM,52,102,36,NO
|
||||
CAULIFLOWER,52,116,36,NO
|
||||
CAULIFLOWER,26,118,37,NO
|
||||
MUSHROOM,59,112,41,NO
|
||||
MUSHROOM,51,90,42,NO
|
||||
MUSHROOM,22,91,43,NO
|
||||
CAULIFLOWER,62,114,43,NO
|
||||
CAULIFLOWER,78,97,43,NO
|
||||
MUSHROOM,60,92,44,NO
|
||||
CAULIFLOWER,88,112,44,NO
|
||||
CAULIFLOWER,12,111,45,NO
|
||||
CAULIFLOWER,53,113,48,NO
|
||||
CAULIFLOWER,68,104,51,NO
|
||||
MUSHROOM,7,117,52,NO
|
||||
CAULIFLOWER,51,113,54,NO
|
||||
PUMPKIN,20,89,69,YES
|
||||
CAULIFLOWER,16,102,55,NO
|
||||
PUMPKIN,21,63,23,YES
|
||||
MUSHROOM,13,111,56,NO
|
||||
CAULIFLOWER,22,95,57,NO
|
||||
MUSHROOM,8,104,58,NO
|
||||
PUMPKIN,23,26,19,YES
|
||||
CAULIFLOWER,58,106,62,NO
|
||||
PUMPKIN,24,68,7,YES
|
||||
PUMPKIN,25,66,96,NO
|
||||
CAULIFLOWER,55,99,63,NO
|
||||
MUSHROOM,74,104,67,NO
|
||||
PUMPKIN,28,34,68,YES
|
||||
CAULIFLOWER,57,102,68,NO
|
||||
PUMPKIN,29,29,61,YES
|
||||
PUMPKIN,46,90,70,NO
|
||||
CABBAGE,46,93,70,NO
|
||||
CAULIFLOWER,29,105,71,NO
|
||||
PUMPKIN,30,28,31,YES
|
||||
MUSHROOM,30,67,24,YES
|
||||
PUMPKIN,30,96,30,NO
|
||||
CABBAGE,30,89,30,YES
|
||||
CABBAGE,31,62,40,YES
|
||||
PUMPKIN,31,65,34,YES
|
||||
MUSHROOM,31,81,17,YES
|
||||
MUSHROOM,31,89,29,YES
|
||||
MUSHROOM,32,20,19,YES
|
||||
CABBAGE,32,25,50,YES
|
||||
MUSHROOM,32,90,22,NO
|
||||
MUSHROOM,32,56,7,YES
|
||||
CABBAGE,33,15,50,YES
|
||||
MUSHROOM,33,32,14,YES
|
||||
PUMPKIN,33,47,59,YES
|
||||
PUMPKIN,19,99,72,NO
|
||||
MUSHROOM,33,63,30,NO
|
||||
CABBAGE,33,65,64,YES
|
||||
CABBAGE,34,27,44,YES
|
||||
CABBAGE,34,44,93,NO
|
||||
MUSHROOM,34,44,22,YES
|
||||
PUMPKIN,51,99,72,NO
|
||||
CABBAGE,34,56,70,NO
|
||||
MUSHROOM,34,56,18,YES
|
||||
CABBAGE,35,21,63,YES
|
||||
PUMPKIN,35,42,48,YES
|
||||
CAULIFLOWER,35,74,12,YES
|
||||
PUMPKIN,35,76,71,NO
|
||||
CAULIFLOWER,36,58,28,YES
|
||||
CABBAGE,36,57,54,YES
|
||||
CAULIFLOWER,36,72,84,NO
|
||||
CAULIFLOWER,36,83,71,NO
|
||||
CABBAGE,36,67,64,YES
|
||||
PUMPKIN,36,82,53,YES
|
||||
CABBAGE,37,47,57,YES
|
||||
MUSHROOM,37,59,13,YES
|
||||
CAULIFLOWER,37,40,15,YES
|
||||
CAULIFLOWER,37,69,16,YES
|
||||
CABBAGE,37,63,60,YES
|
||||
PUMPKIN,37,72,46,YES
|
||||
CABBAGE,38,62,79,NO
|
||||
CAULIFLOWER,38,98,12,NO
|
||||
CAULIFLOWER,38,59,22,YES
|
||||
PUMPKIN,38,73,56,YES
|
||||
CABBAGE,38,74,52,YES
|
||||
PUMPKIN,38,90,39,NO
|
||||
MUSHROOM,38,78,9,YES
|
||||
CABBAGE,39,86,64,NO
|
||||
PUMPKIN,39,31,45,YES
|
||||
PUMPKIN,39,102,53,NO
|
||||
CAULIFLOWER,39,49,14,YES
|
||||
CAULIFLOWER,39,54,81,NO
|
||||
CABBAGE,39,87,57,NO
|
||||
CABBAGE,40,8,32,YES
|
||||
PUMPKIN,40,57,63,YES
|
||||
CABBAGE,40,92,61,NO
|
||||
CAULIFLOWER,40,52,27,YES
|
||||
PUMPKIN,41,8,29,YES
|
||||
CABBAGE,41,25,48,YES
|
||||
CABBAGE,41,43,51,YES
|
||||
CABBAGE,41,52,60,YES
|
||||
CAULIFLOWER,41,20,24,YES
|
||||
MUSHROOM,41,83,25,YES
|
||||
CABBAGE,41,85,37,YES
|
||||
CABBAGE,42,64,41,YES
|
||||
MUSHROOM,42,66,26,YES
|
||||
CABBAGE,42,69,59,YES
|
||||
CAULIFLOWER,42,38,9,YES
|
||||
MUSHROOM,43,15,9,YES
|
||||
MUSHROOM,43,93,22,NO
|
||||
CABBAGE,43,60,38,YES
|
||||
PUMPKIN,43,78,43,YES
|
||||
CAULIFLOWER,43,29,18,YES
|
||||
CAULIFLOWER,43,96,20,NO
|
||||
CAULIFLOWER,43,84,4,YES
|
||||
CABBAGE,61,130,72,NO
|
||||
CABBAGE,44,59,31,YES
|
||||
PUMPKIN,44,64,44,YES
|
||||
CAULIFLOWER,44,62,19,YES
|
||||
CABBAGE,45,35,69,YES
|
||||
MUSHROOM,45,65,27,YES
|
||||
MUSHROOM,45,71,2,YES
|
||||
PUMPKIN,45,83,57,YES
|
||||
CAULIFLOWER,45,31,26,YES
|
||||
CAULIFLOWER,45,61,10,YES
|
||||
CAULIFLOWER,45,76,85,NO
|
||||
MUSHROOM,46,48,24,YES
|
||||
MUSHROOM,10,96,73,NO
|
||||
CABBAGE,62,123,74,NO
|
||||
MUSHROOM,47,37,16,YES
|
||||
MUSHROOM,47,42,41,NO
|
||||
CAULIFLOWER,47,50,11,YES
|
||||
PUMPKIN,11,99,75,NO
|
||||
CABBAGE,16,98,75,NO
|
||||
MUSHROOM,48,77,12,YES
|
||||
CABBAGE,48,106,75,NO
|
||||
CAULIFLOWER,48,32,23,YES
|
||||
CAULIFLOWER,48,44,19,YES
|
||||
CAULIFLOWER,48,98,14,NO
|
||||
CABBAGE,8,124,76,NO
|
||||
MUSHROOM,49,64,4,YES
|
||||
PUMPKIN,59,114,76,NO
|
||||
PUMPKIN,50,119,77,NO
|
||||
CABBAGE,55,116,77,NO
|
||||
MUSHROOM,50,74,21,YES
|
||||
CAULIFLOWER,50,47,25,YES
|
||||
CABBAGE,53,117,78,NO
|
||||
PUMPKIN,55,91,78,NO
|
||||
PUMPKIN,49,91,79,NO
|
||||
CABBAGE,56,125,79,NO
|
||||
MUSHROOM,57,95,79,NO
|
||||
PUMPKIN,8,123,80,NO
|
||||
MUSHROOM,16,99,80,NO
|
||||
PUMPKIN,55,93,80,NO
|
||||
CABBAGE,60,99,80,NO
|
||||
MUSHROOM,13,114,81,NO
|
||||
CAULIFLOWER,20,100,81,NO
|
||||
CABBAGE,49,100,81,NO
|
||||
PUMPKIN,54,92,81,NO
|
||||
CABBAGE,10,94,83,NO
|
||||
PUMPKIN,17,91,83,NO
|
||||
CAULIFLOWER,17,95,84,NO
|
||||
PUMPKIN,53,92,84,NO
|
||||
MUSHROOM,65,110,85,NO
|
||||
PUMPKIN,73,101,85,NO
|
||||
PUMPKIN,18,102,88,NO
|
||||
PUMPKIN,47,120,88,NO
|
||||
PUMPKIN,48,102,89,NO
|
||||
MUSHROOM,60,98,89,NO
|
||||
CABBAGE,68,120,89,NO
|
||||
CABBAGE,58,16,26,NO
|
||||
MUSHROOM,53,107,90,NO
|
||||
CABBAGE,8,92,92,NO
|
||||
MUSHROOM,11,97,92,NO
|
||||
PUMPKIN,14,98,92,NO
|
||||
CAULIFLOWER,58,103,92,NO
|
||||
CABBAGE,59,131,92,NO
|
||||
PUMPKIN,57,104,93,NO
|
||||
MUSHROOM,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
|
||||
MUSHROOM,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
|
|
110
decisiontree.py
110
decisiontree.py
@ -1,59 +1,51 @@
|
||||
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("data/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)
|
||||
"""
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user