From 7add741845345e13a7103fa0121bd61c2f083744 Mon Sep 17 00:00:00 2001 From: trzmielewskiR Date: Thu, 12 May 2022 09:39:25 +0200 Subject: [PATCH] Repaired prediction, changed dataset --- decision_tree/decisionTree.py | 9 +- decision_tree/drzewo_decyzyjne.csv | 170 +++++++++++++++++++++++------ decision_tree/tree_as_txt.txt | 110 ++++++++++++++++--- decision_tree/tree_model | Bin 2729 -> 7076 bytes main.py | 4 + 5 files changed, 239 insertions(+), 54 deletions(-) diff --git a/decision_tree/decisionTree.py b/decision_tree/decisionTree.py index 9ed19a7..f15b77c 100644 --- a/decision_tree/decisionTree.py +++ b/decision_tree/decisionTree.py @@ -11,11 +11,10 @@ time_since_flush = [1,2,3,4,5,6,7,8,9,10] type_of_trash = {"bio":1, "szklo":2, "plastik":3, "papier":4, "mieszane":5} access_to_bin = { "no":1, "yes":2} distance = [1,2,3,4,5,6,7,8,9,10] -decision = [1,2,3,4,5] +decision = [0,1] - decyzje zostaną zmienione z tych z wagami na zero jedynkowe ze względu na pewne trudności w dalszej pracy ''' decisions = ["decision"] -attributes = ["season", "enough_space_in_trashmaster", "time_since_flush", "type_of_trash", "access_to_bin", "distance", - "decision"] +attributes = ["season", "enough_space_in_trashmaster", "time_since_flush", "type_of_trash", "access_to_bin", "distance"] # return tree made from attributes @@ -60,6 +59,10 @@ def tree_to_png(decision_tree): def tree_to_structure(decision_tree): joblib.dump(decision_tree, './decision_tree/tree_model') + +def tree_from_structure(file): + return joblib.load(file) + #drzewo = tree() #tree_as_txt(drzewo) #tree_to_png(drzewo) diff --git a/decision_tree/drzewo_decyzyjne.csv b/decision_tree/drzewo_decyzyjne.csv index e5b77f5..4df73a4 100644 --- a/decision_tree/drzewo_decyzyjne.csv +++ b/decision_tree/drzewo_decyzyjne.csv @@ -2,30 +2,30 @@ season,enough_space_in_trashmaster,time_since_flush,type_of_trash,access_to_bin, 2,2,1,1,2,10,1 2,2,2,2,2,8,1 2,2,3,3,2,6,1 -2,2,4,4,2,4,2 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6,0 +4,2,4,4,1,8,0 +4,2,5,5,2,10,1 +4,2,6,1,2,1,1 +4,1,2,2,2,5,1 +4,1,3,3,2,4,1 +4,1,4,4,1,3,0 +4,1,5,5,1,2,0 +4,1,6,1,1,1,0 +1,2,2,2,2,1,1 +1,2,3,3,2,4,1 +1,2,4,4,2,3,1 +1,2,5,5,2,6,1 +1,2,6,1,2,5,1 +1,2,7,2,2,8,1 +1,2,8,3,2,7,1 +1,2,9,4,2,9,1 +1,2,10,5,2,10,1 +1,2,1,1,2,7,1 +1,2,2,2,2,6,1 +1,2,3,3,2,4,0 +1,2,4,4,2,1,1 +1,2,5,5,2,2,1 +1,2,6,1,2,3,1 +1,2,7,2,2,9,1 +1,2,8,3,2,8,0 +1,2,9,4,2,5,1 +1,2,10,5,2,4,1 +1,2,1,1,2,1,1 +1,2,2,2,1,7,0 +1,2,3,3,1,9,0 +1,2,4,4,1,10,0 +1,2,5,5,1,3,0 +1,2,6,1,1,2,0 +1,2,7,2,1,5,0 +1,2,8,3,1,6,0 +1,2,9,4,1,8,0 +1,2,10,5,1,3,0 +1,2,1,1,1,1,0 +1,2,2,2,1,2,0 +1,2,3,3,1,6,0 +1,2,4,4,1,9,0 +1,2,5,5,1,7,0 +1,2,6,1,1,4,0 +1,2,7,2,1,3,0 +1,2,8,3,1,5,0 +1,2,9,4,1,10,0 +1,2,10,5,1,8,0 +1,2,1,1,2,2,1 +1,1,2,2,2,4,0 +1,1,3,3,2,6,0 +1,1,4,4,2,7,0 +1,1,5,5,2,1,0 +1,1,6,1,2,9,0 +1,1,7,2,2,3,0 +1,1,8,3,2,9,0 +1,1,9,4,2,9,0 +1,1,10,5,2,1,0 diff --git a/decision_tree/tree_as_txt.txt b/decision_tree/tree_as_txt.txt index 3d68d31..28a1fd5 100644 --- a/decision_tree/tree_as_txt.txt +++ b/decision_tree/tree_as_txt.txt @@ -1,16 +1,94 @@ -|--- feature_6 <= 0.50 -| |--- class: 0 -|--- feature_6 > 0.50 -| |--- feature_6 <= 1.50 -| | |--- class: 1 -| |--- feature_6 > 1.50 -| | |--- feature_6 <= 3.50 -| | | |--- feature_6 <= 2.50 -| | | | |--- class: 2 -| | | |--- feature_6 > 2.50 -| | | | |--- class: 3 -| | |--- feature_6 > 3.50 -| | | |--- feature_6 <= 4.50 -| | | | |--- class: 4 -| | | |--- feature_6 > 4.50 -| | | | |--- class: 5 +|--- feature_4 <= 1.50 +| |--- feature_5 <= 1.50 +| | |--- feature_2 <= 6.50 +| | | |--- class: 0 +| | |--- feature_2 > 6.50 +| | | |--- feature_0 <= 3.00 +| | | | |--- class: 1 +| | | |--- feature_0 > 3.00 +| | | | |--- class: 0 +| |--- feature_5 > 1.50 +| | |--- class: 0 +|--- feature_4 > 1.50 +| |--- feature_1 <= 1.50 +| | |--- feature_0 <= 3.50 +| | | |--- class: 0 +| | |--- feature_0 > 3.50 +| | | |--- class: 1 +| |--- feature_1 > 1.50 +| | |--- feature_0 <= 3.50 +| | | |--- feature_0 <= 1.50 +| | | | |--- feature_3 <= 2.50 +| | | | | |--- class: 1 +| | | | |--- feature_3 > 2.50 +| | | | | |--- feature_3 <= 3.50 +| | | | | | |--- feature_5 <= 7.50 +| | | | | | | |--- feature_2 <= 5.50 +| | | | | | | | |--- class: 0 +| | | | | | | |--- feature_2 > 5.50 +| | | | | | | | |--- class: 1 +| | | | | | |--- feature_5 > 7.50 +| | | | | | | |--- class: 0 +| | | | | |--- feature_3 > 3.50 +| | | | | | |--- class: 1 +| | | |--- feature_0 > 1.50 +| | | | |--- feature_3 <= 1.50 +| | | | | |--- feature_5 <= 2.50 +| | | | | | |--- feature_5 <= 1.50 +| | | | | | | |--- class: 1 +| | | | | | |--- feature_5 > 1.50 +| | | | | | | |--- feature_0 <= 2.50 +| | | | | | | | |--- class: 0 +| | | | | | | |--- feature_0 > 2.50 +| | | | | | | | |--- class: 1 +| | | | | |--- feature_5 > 2.50 +| | | | | | |--- class: 1 +| | | | |--- feature_3 > 1.50 +| | | | | |--- feature_2 <= 3.50 +| | | | | | |--- feature_0 <= 2.50 +| | | | | | | |--- feature_5 <= 2.00 +| | | | | | | | |--- class: 1 +| | | | | | | |--- feature_5 > 2.00 +| | | | | | | | |--- feature_5 <= 4.00 +| | | | | | | | | |--- class: 0 +| | | | | | | | |--- feature_5 > 4.00 +| | | | | | | | | |--- feature_3 <= 2.50 +| | | | | | | | | | |--- feature_5 <= 7.00 +| | | | | | | | | | | |--- class: 0 +| | | | | | | | | | |--- feature_5 > 7.00 +| | | | | | | | | | | |--- class: 1 +| | | | | | | | | |--- feature_3 > 2.50 +| | | | | | | | | | |--- class: 1 +| | | | | | |--- feature_0 > 2.50 +| | | | | | | |--- class: 1 +| | | | | |--- feature_2 > 3.50 +| | | | | | |--- feature_5 <= 1.50 +| | | | | | | |--- class: 0 +| | | | | | |--- feature_5 > 1.50 +| | | | | | | |--- feature_3 <= 2.50 +| | | | | | | | |--- feature_5 <= 5.00 +| | | | | | | | | |--- class: 1 +| | | | | | | | |--- feature_5 > 5.00 +| | | | | | | | | |--- class: 0 +| | | | | | | |--- feature_3 > 2.50 +| | | | | | | | |--- feature_5 <= 5.50 +| | | | | | | | | |--- feature_0 <= 2.50 +| | | | | | | | | | |--- feature_2 <= 4.50 +| | | | | | | | | | | |--- class: 0 +| | | | | | | | | | |--- feature_2 > 4.50 +| | | | | | | | | | | |--- class: 0 +| | | | | | | | | |--- feature_0 > 2.50 +| | | | | | | | | | |--- feature_2 <= 4.50 +| | | | | | | | | | | |--- class: 0 +| | | | | | | | | | |--- feature_2 > 4.50 +| | | | | | | | | | | |--- truncated branch of depth 2 +| | | | | | | | |--- feature_5 > 5.50 +| | | | | | | | | |--- feature_5 <= 6.50 +| | | | | | | | | | |--- class: 1 +| | | | | | | | | |--- feature_5 > 6.50 +| | | | | | | | | | |--- feature_2 <= 8.50 +| | | | | | | | | | | |--- truncated branch of depth 3 +| | | | | | | | | | |--- feature_2 > 8.50 +| | | | | | | | | | | |--- truncated branch of depth 4 +| | |--- feature_0 > 3.50 +| | | |--- class: 1 diff --git a/decision_tree/tree_model b/decision_tree/tree_model index b8b86191f004fdf8dfbccdcfb91ff75fcb405c35..ef984c8271342ae5cf51591f715e0fdd93474b7f 100644 GIT binary patch literal 7076 zcmdT}U2Ggz6&^clXT8}tYsYrn;JUUGf?LXBCnR-9(zziepJ_IC?#RG8f+;hfz z?>b^-Dxutm{pOr|?m6e4zge#@XIB2&qa-UD^L>y(#+m0PaS-(}c1InbFs_6%DG|1&B-T`wn+LEUm0X3r~o2R(n ziW23S?j=(XLXSFJjs_XcWHhH)OE`H?cWTXs<_CIUQi)Nf)o!#x>iI?Lmf@MYZ^msZ zlk0DP;yIOR@M(d*1vJD#4I2tN5^0?>e z7oYR=R;xXHSwE~M*5aryITc4+otn;MX^f*j-_l!VT4o^(YggmNc($}9>UkwDm&;H6o37-eqy}*{%IWob^Chj(&|C4fuzI=INX!+D zre_u#VLh-DqdCnpji%!VUT6e4SK(4Qa4F~Zl$2$+*U$_aTf@(p4tvPCTPm!Os&1yz zPqD5CwlnYcU2*#t-K|&M?4mm`Tk4^=aC4wA@jvHotMpR&(+h5%`tNREbO-4T5?!yj zJLFrqh3d8E-J#jUhEH?Wbll;}m#6~MX@=)5T1>iOvP=Y??pqDrr#0yAtQ4q3U^h(7 zw;j5_R1ba29jR<*Y#K$axx^2+qX|zp4Ab|ups7`D#~rI=sa(yb#X}FfyUf5HuNGHY zl*v{!=%mG$)Ig~}$~jsy3|e8}YpjT~&`ervjq#?j9l z67{@4>SM!zmi4eW92l3jHk$}kQK?_LR!@4Z`NUcdrNhG-C=F7-X$8@G z3Y{P>Jx#kH=~_wW)2YsxXv_Bw9$GJVYhQUb%GJ%KKr<}6UW=n`UNSF$+6rw-hfrYA z31KyvOcvWeW(iC@fQb}GyZFE{YnrqZBtDm|`I2%awoX&bQanSkK=B!t#ih0^TKmNU zW;ra4Q^`f^Txp8pv-IRF#j}*2yAp?`1==G8%rs`0l^L=XW z0@U3AR75{U2-0j|bgnGnygRDshtjn@j33u?S8ex^J>SdE&7OO*{Ssu63;>-66!osD zwKqSX3xD;g`f~d@>^6Vm9KWmX1v_8f&|ZPOJ-PgsXWqW8ihhiA*|+Q8 z^tk%F>OQdZFre5ESTCLR`4y0#1r+_6Ae?>w)R|aE-G48T=Pu5TuWcBYHT6AKE)%ON z&LJ+gu<862!OlFOoWFBBE5G<@u&Rph$H&OmL4FQU%-;y%?9RMzwywK9C;Fcy`@z2> z8~Qm${&?>1*UNueRq=ht#SV}IAb$u@giPAE@_YIlAb1c^tc&4vPRQ}cPLr`$(Rfqx}Haeoit z?Ein>yS*QNzvX@(B`f&CjruR>^^pETEC1F*e+B8iia(8=TmRYX#tZ!NUk2pp6(>&l2K$M@6=q%6*E@>anA)*+f%*Q;=fu8+qP9!c-sd(Z7^0$;taDhX~>+bnw9r3ZOra0w41wpL;~wm;FF}cnBg&yZj3*+><9=g@9_^!FD35w@ANv&fs85#1eZ+h1BOmXFD4#<+9s7i9 u=#WRn(!MN*G$I~Dq(g8Dp2KQX(BS8F?SkpCf3?wn@5~qHiu>cRTKo@9Tn7dK delta 1067 zcmZ2tzEYH>fo1CVjV#L<8QCYVVU*zLVNEHiEJ&R)`55DBpimLhVc`f41_p+d)a12AUiPVxp$;pQAQ0^=zV25A4IEH|~Ek?}>d1 zR2)J@I!u1YrXgv8BIx4)4?VEvAND6R_l2G3dugwOqRtJXnHxn=&4Crl=KyI|=5g4S z*8Tpd*>ihEWOWS=4zQSD2V278P$2Z}?)npV?S+xmF&Kj_nQX>pA<2Uxq2a&@<#T}z z5ORo+mwN4-eAk{2MV$`B06tCukXI+?u?b8r6I1lz1_l;eJ1hysg2N1=&&L5mt3hcQ zD6Ijdm7uf;l=g9$ypUaZ@&OV diff --git a/main.py b/main.py index 81e7821..e7c2476 100644 --- a/main.py +++ b/main.py @@ -20,6 +20,10 @@ def printTree(): decisionTree.tree_as_txt(tree) decisionTree.tree_to_png(tree) decisionTree.tree_to_structure(tree) + drzewo = decisionTree.tree_from_structure('./decision_tree/tree_model') + print("Dla losowych danych predykcja czy wziąć kosz to: ") + dec = decisionTree.decision(drzewo, 4, 2, 7, 4, 2, 3) + print(dec) class Game():