package com.imsl.test.example.datamining.decisionTree; import com.imsl.datamining.decisionTree.*; /** *

Fits a decision tree to categorical data using CHAID and * prints the decision tree.

*

* This example uses the CHAID * method on simulated categorical data and demonstrates printing the tree * structure with and without custom * labels. *

* @see Code * @see Output */ public class DecisionTreeEx2 { public static void main(String[] args) throws Exception { double[][] xy = { {2, 0, 2}, {1, 0, 0}, {2, 1, 3}, {0, 1, 0}, {1, 2, 0}, {2, 2, 3}, {2, 2, 3}, {0, 1, 0}, {0, 0, 0}, {0, 1, 0}, {1, 2, 0}, {2, 0, 2}, {0, 2, 0}, {2, 0, 1}, {0, 0, 0}, {2, 0, 1}, {1, 0, 0}, {0, 2, 0}, {2, 0, 1}, {1, 2, 0}, {0, 2, 2}, {2, 1, 3}, {1, 1, 0}, {2, 2, 3}, {1, 2, 0}, {2, 2, 3}, {2, 0, 1}, {2, 1, 3}, {1, 2, 0}, {1, 1, 0} }; DecisionTree.VariableType[] varType = { DecisionTree.VariableType.CATEGORICAL, DecisionTree.VariableType.CATEGORICAL, DecisionTree.VariableType.CATEGORICAL }; String responseName = "Response"; String[] names = {"Var1", "Var2"}; String[] classNames = {"c1", "c2", "c3", "c4"}; String[] varLabels = {"L1", "L2", "L3", "A", "B", "C"}; CHAID dt = new CHAID(xy, 2, varType); dt.setMinObsPerChildNode(5); dt.setMinObsPerNode(10); dt.setMaxNodes(50); dt.fitModel(); System.out.println("\nGenerated labels:"); dt.printDecisionTree(true); System.out.println("\nCustom labels:"); dt.printDecisionTree(responseName, names, classNames, varLabels, false); } }