From b12383df6d8f27e5bb6981782f7a111dc381f834 Mon Sep 17 00:00:00 2001 From: Maxim Derksen Date: Sun, 15 Nov 2020 14:40:34 +0100 Subject: [PATCH] Entscheidungsbaum-erstellung fertiggestellt --- DecisionTreeBuilder.java | 58 ++++++++++-------- package.bluej | 127 +++++++++++++++++++++------------------ 2 files changed, 102 insertions(+), 83 deletions(-) diff --git a/DecisionTreeBuilder.java b/DecisionTreeBuilder.java index 07f3c7f..043a079 100644 --- a/DecisionTreeBuilder.java +++ b/DecisionTreeBuilder.java @@ -5,17 +5,20 @@ public class DecisionTreeBuilder { // Wurzel des Entscheidungsbaums + private BinaryTree Vorhersage2; + private BinaryTree Wind; + private BinaryTree Feuchtigkeit; + private BinaryTree Vorhersage; private BinaryTree decisionTree; public DecisionTreeBuilder() { // Vorbereiten der Klassifikationen (Blätter) BinaryTree classYes = new BinaryTree<>( - new Classification("ja") - ); + new Classification("ja") + ); BinaryTree classNo = new BinaryTree<>( - new Classification("nein") - ); - + new Classification("nein") + ); // TODO: Hier den Entscheidungsbaum aufbauen. // @@ -28,11 +31,14 @@ public class DecisionTreeBuilder { // ); // usw... // Die Wurzel zuletzt - decisionTree = new BinaryTree<>( - new Decision("vorhersage", "regnerisch"), - feuchtigkeit, - vorhersage - ); + + Feuchtigkeit = new BinaryTree<>(new Decision("feuchtigkeit", "hoch") ,classNo,classYes); + + Wind = new BinaryTree<>(new Decision("wind","stark"),classNo,classYes); + + Vorhersage2 = new BinaryTree<>(new Decision("vorhersage", "regnerisch"),Wind,classYes); + + Vorhersage = new BinaryTree<>(new Decision("vorhersage" , "sonnig"),Feuchtigkeit,Vorhersage); } /** @@ -66,7 +72,7 @@ public class DecisionTreeBuilder { String result = ""; while( result.equals("") || result.equals("left") - || result.equals("right") ) { + || result.equals("right") ) { // TODO: Impementiere den Durchlauf durch den Entschiedungsbaum, // indem bei jedem inneren Knoten die Entscheidung getroffen wird, // ob links oder rechts weitergemacht wird. @@ -81,21 +87,21 @@ public class DecisionTreeBuilder { */ public Dataset[] getTestdata() { String[][] testdata = { - {"sonnig", "heiß", "hoch", "schwach"}, - {"sonnig", "heiß", "hoch", "stark"}, - {"bewölkt", "heiß", "hoch", "schwach"}, - {"regnerisch", "mild", "hoch", "schwach"}, - {"regnerisch", "kalt", "normal", "schwach"}, - {"regnerisch", "kalt", "normal", "stark"}, - {"bewölkt", "mild", "hoch", "stark"}, - {"sonnig", "mild", "hoch", "schwach"}, - {"sonnig", "kalt", "normal", "schwach"}, - {"regnerisch", "mild", "normal", "schwach"}, - {"sonnig", "mild", "normal", "stark"}, - {"bewölkt", "heiß", "normal", "schwach"}, - {"bewölkt", "kalt", "normal", "stark"}, - {"regnerisch", "mild", "hoch", "stark"} - }; + {"sonnig", "heiß", "hoch", "schwach"}, + {"sonnig", "heiß", "hoch", "stark"}, + {"bewölkt", "heiß", "hoch", "schwach"}, + {"regnerisch", "mild", "hoch", "schwach"}, + {"regnerisch", "kalt", "normal", "schwach"}, + {"regnerisch", "kalt", "normal", "stark"}, + {"bewölkt", "mild", "hoch", "stark"}, + {"sonnig", "mild", "hoch", "schwach"}, + {"sonnig", "kalt", "normal", "schwach"}, + {"regnerisch", "mild", "normal", "schwach"}, + {"sonnig", "mild", "normal", "stark"}, + {"bewölkt", "heiß", "normal", "schwach"}, + {"bewölkt", "kalt", "normal", "stark"}, + {"regnerisch", "mild", "hoch", "stark"} + }; Dataset[] data = new Dataset[testdata.length]; for( int i = 0; i < testdata.length; i++ ) { diff --git a/package.bluej b/package.bluej index 460a419..63eb250 100644 --- a/package.bluej +++ b/package.bluej @@ -1,44 +1,50 @@ #BlueJ package file -dependency1.from=DecisionNode +dependency1.from=Classification dependency1.to=Dataset dependency1.type=UsesDependency -dependency2.from=Classification -dependency2.to=Dataset +dependency10.from=DecisionTreeBuilder +dependency10.to=Dataset +dependency10.type=UsesDependency +dependency2.from=DecisionTreeTest +dependency2.to=DecisionTreeBuilder dependency2.type=UsesDependency -dependency3.from=Decision +dependency3.from=DecisionTreeTest dependency3.to=Dataset dependency3.type=UsesDependency -dependency4.from=DecisionTreeBuilder -dependency4.to=BinaryTree +dependency4.from=DecisionNode +dependency4.to=Dataset dependency4.type=UsesDependency -dependency5.from=DecisionTreeBuilder -dependency5.to=DecisionNode +dependency5.from=Decision +dependency5.to=Dataset dependency5.type=UsesDependency dependency6.from=DecisionTreeBuilder -dependency6.to=Classification +dependency6.to=BinaryTree dependency6.type=UsesDependency dependency7.from=DecisionTreeBuilder -dependency7.to=Decision +dependency7.to=DecisionNode dependency7.type=UsesDependency dependency8.from=DecisionTreeBuilder -dependency8.to=Dataset +dependency8.to=Classification dependency8.type=UsesDependency -editor.fx.0.height=722 -editor.fx.0.width=800 -editor.fx.0.x=388 -editor.fx.0.y=50 -objectbench.height=66 -objectbench.width=1201 +dependency9.from=DecisionTreeBuilder +dependency9.to=Decision +dependency9.type=UsesDependency +editor.fx.0.height=1416 +editor.fx.0.width=2576 +editor.fx.0.x=-8 +editor.fx.0.y=-8 +objectbench.height=196 +objectbench.width=2536 package.divider.horizontal=0.6 -package.divider.vertical=0.8983286908077994 -package.editor.height=622 -package.editor.width=1078 -package.editor.x=39 -package.editor.y=24 -package.frame.height=776 -package.frame.width=1241 -package.numDependencies=8 -package.numTargets=6 +package.divider.vertical=0.8457446808510638 +package.editor.height=1106 +package.editor.width=2425 +package.editor.x=0 +package.editor.y=0 +package.frame.height=1416 +package.frame.width=2576 +package.numDependencies=10 +package.numTargets=7 package.showExtends=true package.showUses=true project.charset=UTF-8 @@ -47,45 +53,52 @@ readme.name=@README readme.width=47 readme.x=10 readme.y=10 -target1.height=40 -target1.name=Classification +target1.height=60 +target1.name=DecisionTreeBuilder target1.showInterface=false target1.type=ClassTarget -target1.width=210 -target1.x=40 -target1.y=460 -target2.height=50 -target2.name=Decision +target1.width=270 +target1.x=580 +target1.y=230 +target2.height=40 +target2.name=Dataset target2.showInterface=false target2.type=ClassTarget -target2.width=190 -target2.x=300 -target2.y=460 -target3.height=120 -target3.name=BinaryTree +target2.width=270 +target2.x=430 +target2.y=30 +target3.height=40 +target3.name=Classification target3.showInterface=false target3.type=ClassTarget -target3.width=440 -target3.x=890 -target3.y=250 -target4.height=40 -target4.name=Dataset +target3.width=210 +target3.x=40 +target3.y=460 +target4.height=120 +target4.name=BinaryTree target4.showInterface=false target4.type=ClassTarget -target4.width=270 -target4.x=430 -target4.y=30 +target4.width=440 +target4.x=870 +target4.y=420 target5.height=50 -target5.name=DecisionNode +target5.name=DecisionTreeTest target5.showInterface=false -target5.type=AbstractTarget -target5.width=110 -target5.x=210 -target5.y=290 -target6.height=60 -target6.name=DecisionTreeBuilder +target5.type=ClassTarget +target5.width=130 +target5.x=70 +target5.y=10 +target6.height=50 +target6.name=DecisionNode target6.showInterface=false -target6.type=ClassTarget -target6.width=270 -target6.x=580 -target6.y=230 +target6.type=AbstractTarget +target6.width=110 +target6.x=210 +target6.y=290 +target7.height=50 +target7.name=Decision +target7.showInterface=false +target7.type=ClassTarget +target7.width=190 +target7.x=300 +target7.y=460