Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

61
LINES

< > BotCompany Repo | #1010870 // Test decision trees [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 112K of libraries. Click here for Pure Java version (761L/6K).

!7

lib 1010869 // decision trees
lib 1004016 // slf4j
lib 1004015 // slf4j simple

import dt.DecisionTree;
import dt.UnknownDecisionException;

p {
  //DecisionTree tree = makeOutlookTree();
  testOutlookOvercastApplyReturnsTrue();
  testUnknownDecisionThrowsException();
  print("OK");
}

static void testOutlookOvercastApplyReturnsTrue() ctex {
  SS case1 = lithashmap(
    "Outlook", "Overcast",
    "Temperature", "Hot",
    "Humidity", "High",
    "Wind", "Strong");
  assertTrue(makeOutlookTree().apply(case1));
} 

static void testUnknownDecisionThrowsException() {
  DecisionTree tree = new DecisionTree().setAttributes(new String[]{"Outlook"})
    .setDecisions("Outlook", new String[]{"Sunny", "Overcast"});

  try {
    tree.addExample(new String[]{"Rain"}, false);
    fail("no exception");
  } catch (UnknownDecisionException e) {
    // ok
  }
}

static DecisionTree makeOutlookTree() {
  try {
    // example data from http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm
    
    return new DecisionTree().setAttributes(new String[]{"Outlook",  "Temperature", "Humidity", "Wind"})
                    .addExample(   new String[]{"Sunny",    "Hot",         "High",     "Weak"}, false)
                    .addExample(   new String[]{"Sunny",    "Hot",         "High",     "Strong"}, false)
                    .addExample(   new String[]{"Overcast", "Hot",         "High",     "Weak"}, true)
                    .addExample(   new String[]{"Rain",     "Mild",        "High",     "Weak"}, true)
                    .addExample(   new String[]{"Rain",     "Cool",        "Normal",   "Weak"}, true)
                    .addExample(   new String[]{"Rain",     "Cool",        "Normal",   "Strong"}, false)
                    .addExample(   new String[]{"Overcast", "Cool",        "Normal",   "Strong"}, true)
                    .addExample(   new String[]{"Sunny",    "Mild",        "High",     "Weak"}, false)
                    .addExample(   new String[]{"Sunny",    "Cool",        "Normal",   "Weak"}, true)
                    .addExample(   new String[]{"Rain",     "Mild",        "Normal",   "Weak"}, true)
                    .addExample(   new String[]{"Sunny",    "Mild",        "Normal",   "Strong"}, true)
                    .addExample(   new String[]{"Overcast", "Mild",        "High",     "Strong"}, true)
                    .addExample(   new String[]{"Overcast", "Hot",         "Normal",   "Weak"}, true)
                    .addExample(   new String[]{"Rain",     "Mild",        "High",     "Strong"}, false);
                    
  } catch (UnknownDecisionException e) {
    throw rethrow(e);
  }
}

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: 329 / 835
Version history: 7 change(s)
Referenced in: [show references]