package com.imsl.test.example.datamining.decisionTree;
import com.imsl.datamining.decisionTree.*;
/**
*
* Fits a decision tree to the golf data using C45 and ALACART.
*
*
* In this example, we use a small data set with response variable, Play, which
* indicates whether a golfer plays (1) or does not play (0) golf under weather
* conditions measured by Temperature, Humidity, Outlook (Sunny (0), Overcast
* (1), Rainy (2)), and Wind (True (0), False (1)). A decision tree is generated
* by C45
* and the ALACART
* class. The control parameters are adjusted because of the small data size and
* no cross-validation or pruning is performed. The maximal trees are printed
* out using the method, DecisionTree.printDecisionTree
* Notice that C45
splits on Outlook, then Humidity and Wind, while
* ALACART
splits on Outlook, then Temperature.
*
* @see Code
* @see Output
*
*/
public class DecisionTreeEx1 {
public static void main(String[] args) throws Exception {
int golfResponseIdx = 4;
double[][] golfXY = {
{0, 85, 85, 0, 0}, {0, 80, 90, 1, 0}, {1, 83, 78, 0, 1},
{2, 70, 96, 0, 1}, {2, 68, 80, 0, 1}, {2, 65, 70, 1, 0},
{1, 64, 65, 1, 1}, {0, 72, 95, 0, 0}, {0, 69, 70, 0, 1},
{2, 75, 80, 0, 1}, {0, 75, 70, 1, 1}, {1, 72, 90, 1, 1},
{1, 81, 75, 0, 1}, {2, 71, 80, 1, 0}
};
DecisionTree.VariableType[] golfVarType = {
DecisionTree.VariableType.CATEGORICAL,
DecisionTree.VariableType.QUANTITATIVE_CONTINUOUS,
DecisionTree.VariableType.QUANTITATIVE_CONTINUOUS,
DecisionTree.VariableType.CATEGORICAL,
DecisionTree.VariableType.CATEGORICAL
};
String[] names = {
"Outlook", "Temperature", "Humidity", "Wind", "Play"
};
String[] classNames = {"Don't Play", "Play"};
String[] varLevels = {"Sunny", "Overcast", "Rainy", "False", "True"};
C45 dt = new C45(golfXY, golfResponseIdx, golfVarType);
dt.setMinObsPerChildNode(2);
dt.setMinObsPerNode(3);
dt.setMaxNodes(50);
dt.fitModel();
System.out.println("\n\nDecision Tree using Method C4.5:");
dt.printDecisionTree(null, names, classNames,
varLevels, true);
ALACART adt = new ALACART(golfXY, golfResponseIdx, golfVarType);
adt.setMinObsPerChildNode(2);
adt.setMinObsPerNode(3);
adt.setMaxNodes(50);
adt.fitModel();
System.out.println("\n\nDecision Tree using Method ALACART:");
adt.printDecisionTree(null, names, classNames,
varLevels, true);
}
}