org.knime.base.node.mine.decisiontree2.model
Class DecisionTree

java.lang.Object
  extended by org.knime.base.node.mine.decisiontree2.model.DecisionTree
All Implemented Interfaces:
Serializable

public class DecisionTree
extends Object
implements Serializable

A Wrapper for a decision tree, allowing for save/load to ModelContent objects.

Author:
Michael Berthold, University of Konstanz, Christoph Sieb, University of Konstanz
See Also:
Serialized Form

Constructor Summary
DecisionTree(DecisionTreeNode rootNode, String classifyColumn)
          Create DecisionTree based on a root node to which the remainder of the tree is already attached.
DecisionTree(DecisionTreeNode rootNode, String classifyColumn, PMMLMissingValueStrategy mvStrategy)
          Create DecisionTree based on a root node to which the remainder of the tree is already attached.
DecisionTree(DecisionTreeNode rootNode, String classifyColumn, PMMLMissingValueStrategy mvStrategy, PMMLNoTrueChildStrategy ntcStrategy)
          Create DecisionTree based on a root node to which the remainder of the tree is already attached.
DecisionTree(ModelContentRO pConf)
          Create Decision Tree based on an ModelContent object.
 
Method Summary
 void addCoveredColor(DataRow row, DataTableSpec spec)
          Add color of a new pattern to this tree.
 void addCoveredPattern(DataRow row, DataTableSpec spec)
          Add a new pattern to this tree for HiLiting purposes.
 DataCell classifyPattern(DataRow row, DataTableSpec spec)
          Classify a new pattern given as a row of values.
 LinkedHashMap<DataCell,Double> getClassCounts(DataRow row, DataTableSpec spec)
          Determine class counts for a new pattern given as a row of values.
 String getClassifyColumn()
           
 DecisionTreeNodeLeaf getFirstLeafDFS()
          Returns the first leaf according to a depth first traversal.
 PMMLMissingValueStrategy getMVStrategy()
           
 PMMLNoTrueChildStrategy getNTCStrategy()
           
 int getNumberNodes()
          Returns the number decision tree nodes.
 DecisionTreeNode getRootNode()
           
 void loadFromPredictorParams(ModelContentRO pConf)
          Load Decision Tree from a ModelContent object.
 void resetColorInformation()
          Clean all color information in the entire tree.
 void saveToPredictorParams(ModelContentWO pConf, boolean saveKeysAndPatterns)
          Save decision tree to a ModelContent object.
 void setRoot(DecisionTreeNode root)
          Sets a new root node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecisionTree

public DecisionTree(DecisionTreeNode rootNode,
                    String classifyColumn,
                    PMMLMissingValueStrategy mvStrategy,
                    PMMLNoTrueChildStrategy ntcStrategy)
Create DecisionTree based on a root node to which the remainder of the tree is already attached.

Parameters:
rootNode - the node to attach everything to
classifyColumn - name of attribute to classify with this tree
mvStrategy - the strategy to to apply in case of missing values
ntcStrategy - the strategy to apply when no branch is found

DecisionTree

public DecisionTree(DecisionTreeNode rootNode,
                    String classifyColumn,
                    PMMLMissingValueStrategy mvStrategy)
Create DecisionTree based on a root node to which the remainder of the tree is already attached.

Parameters:
rootNode - the node to attach everything to
classifyColumn - name of attribute to classify with this tree
mvStrategy - the strategy to to apply in case of missing values

DecisionTree

public DecisionTree(DecisionTreeNode rootNode,
                    String classifyColumn)
Create DecisionTree based on a root node to which the remainder of the tree is already attached.

Parameters:
rootNode - the node to attach everything to
classifyColumn - name of attribute to classify with this tree

DecisionTree

public DecisionTree(ModelContentRO pConf)
             throws InvalidSettingsException
Create Decision Tree based on an ModelContent object.

Parameters:
pConf - configuration object to load decision tree from
Throws:
InvalidSettingsException - if something goes wrong
Method Detail

getRootNode

public DecisionTreeNode getRootNode()
Returns:
root node of tree

classifyPattern

public final DataCell classifyPattern(DataRow row,
                                      DataTableSpec spec)
                               throws Exception
Classify a new pattern given as a row of values. Returns the class with the maximum count.

Parameters:
row - input pattern
spec - the corresponding table spec
Returns:
class of pattern the decision tree predicts
Throws:
Exception - if something went wrong (unknown attriubte for example)

addCoveredPattern

public final void addCoveredPattern(DataRow row,
                                    DataTableSpec spec)
                             throws Exception
Add a new pattern to this tree for HiLiting purposes. Stores pattern ID and color (if available) in the leaves.

Parameters:
row - input pattern
spec - the corresponding table spec
Throws:
Exception - if something went wrong (unknown attriubte for example)

addCoveredColor

public final void addCoveredColor(DataRow row,
                                  DataTableSpec spec)
                           throws Exception
Add color of a new pattern to this tree. Does NOT store pattern ID but only it's color (if available) in the leaves.

Parameters:
row - input pattern
spec - the corresponding table spec
Throws:
Exception - if something went wrong (unknown attriubte for example)

getClassCounts

public LinkedHashMap<DataCell,Double> getClassCounts(DataRow row,
                                                     DataTableSpec spec)
                                              throws Exception
Determine class counts for a new pattern given as a row of values. Returns a HashMap listing counts for all classes.

Parameters:
row - input pattern
spec - the corresponding table spec
Returns:
HashMap class/count
Throws:
Exception - if something went wrong (unknown attriubte for example)

resetColorInformation

public void resetColorInformation()
Clean all color information in the entire tree.


saveToPredictorParams

public void saveToPredictorParams(ModelContentWO pConf,
                                  boolean saveKeysAndPatterns)
Save decision tree to a ModelContent object.

Parameters:
pConf - configuration object to attach decision tree to
saveKeysAndPatterns - whether to save the keys and patterns

loadFromPredictorParams

public void loadFromPredictorParams(ModelContentRO pConf)
                             throws InvalidSettingsException
Load Decision Tree from a ModelContent object.

Parameters:
pConf - configuration object to load decision tree from
Throws:
InvalidSettingsException - if something goes wrong

getNumberNodes

public int getNumberNodes()
Returns the number decision tree nodes.

Returns:
the number decision tree nodes

getFirstLeafDFS

public DecisionTreeNodeLeaf getFirstLeafDFS()
Returns the first leaf according to a depth first traversal.

Returns:
the first leaf according to a depth first traversal

setRoot

public void setRoot(DecisionTreeNode root)
Sets a new root node.

Parameters:
root - the new root to set

getClassifyColumn

public String getClassifyColumn()
Returns:
name of attribute to classify with this tree

getMVStrategy

public PMMLMissingValueStrategy getMVStrategy()
Returns:
the missing value strategy

getNTCStrategy

public PMMLNoTrueChildStrategy getNTCStrategy()
Returns:
the noTrueChildStrategy


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.