Download Jar. Uses 112K of libraries. Click here for Pure Java version (761L/6K).
1 | !7 |
2 | |
3 | lib 1010869 // decision trees |
4 | lib 1004016 // slf4j |
5 | lib 1004015 // slf4j simple |
6 | |
7 | import dt.DecisionTree; |
8 | import dt.UnknownDecisionException; |
9 | |
10 | p { |
11 | //DecisionTree tree = makeOutlookTree(); |
12 | testOutlookOvercastApplyReturnsTrue(); |
13 | testUnknownDecisionThrowsException(); |
14 | print("OK"); |
15 | } |
16 | |
17 | static void testOutlookOvercastApplyReturnsTrue() ctex { |
18 | SS case1 = lithashmap( |
19 | "Outlook", "Overcast", |
20 | "Temperature", "Hot", |
21 | "Humidity", "High", |
22 | "Wind", "Strong"); |
23 | assertTrue(makeOutlookTree().apply(case1)); |
24 | } |
25 | |
26 | static void testUnknownDecisionThrowsException() { |
27 | DecisionTree tree = new DecisionTree().setAttributes(new String[]{"Outlook"}) |
28 | .setDecisions("Outlook", new String[]{"Sunny", "Overcast"}); |
29 | |
30 | try { |
31 | tree.addExample(new String[]{"Rain"}, false); |
32 | fail("no exception"); |
33 | } catch (UnknownDecisionException e) { |
34 | // ok |
35 | } |
36 | } |
37 | |
38 | static DecisionTree makeOutlookTree() { |
39 | try { |
40 | // example data from http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm |
41 | |
42 | return new DecisionTree().setAttributes(new String[]{"Outlook", "Temperature", "Humidity", "Wind"}) |
43 | .addExample( new String[]{"Sunny", "Hot", "High", "Weak"}, false) |
44 | .addExample( new String[]{"Sunny", "Hot", "High", "Strong"}, false) |
45 | .addExample( new String[]{"Overcast", "Hot", "High", "Weak"}, true) |
46 | .addExample( new String[]{"Rain", "Mild", "High", "Weak"}, true) |
47 | .addExample( new String[]{"Rain", "Cool", "Normal", "Weak"}, true) |
48 | .addExample( new String[]{"Rain", "Cool", "Normal", "Strong"}, false) |
49 | .addExample( new String[]{"Overcast", "Cool", "Normal", "Strong"}, true) |
50 | .addExample( new String[]{"Sunny", "Mild", "High", "Weak"}, false) |
51 | .addExample( new String[]{"Sunny", "Cool", "Normal", "Weak"}, true) |
52 | .addExample( new String[]{"Rain", "Mild", "Normal", "Weak"}, true) |
53 | .addExample( new String[]{"Sunny", "Mild", "Normal", "Strong"}, true) |
54 | .addExample( new String[]{"Overcast", "Mild", "High", "Strong"}, true) |
55 | .addExample( new String[]{"Overcast", "Hot", "Normal", "Weak"}, true) |
56 | .addExample( new String[]{"Rain", "Mild", "High", "Strong"}, false); |
57 | |
58 | } catch (UnknownDecisionException e) { |
59 | throw rethrow(e); |
60 | } |
61 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1010870 |
Snippet name: | Test decision trees [OK] |
Eternal ID of this version: | #1010870/8 |
Text MD5: | de57a93efd095b9c0e7888e3cee54701 |
Transpilation MD5: | 3155601a62cb78a050d54ad97194e089 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-10-05 00:57:50 |
Source code size: | 2704 bytes / 61 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 462 / 1103 |
Version history: | 7 change(s) |
Referenced in: | [show references] |