Package weka.classifiers.trees.lmt

# Class LMTNode

java.lang.Object
weka.classifiers.AbstractClassifier
weka.classifiers.trees.lmt.LogisticBase
weka.classifiers.trees.lmt.LMTNode

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Classifier`, `BatchPredictor`, `CapabilitiesHandler`, `CapabilitiesIgnorer`, `CommandlineRunnable`, `OptionHandler`, `RevisionHandler`, `WeightedInstancesHandler`

public class LMTNode extends LogisticBase
Class for logistic model tree structure.

Version:
  $Revision: 11566 $
Author:
  Niels Landwehr, Marc Sumner
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `double`
  `m_alpha`
  Alpha-value (for pruning) at the node
  `double`
  `m_numIncorrectModel`
  Weighted number of training examples currently misclassified by the logistic model at the node
  `double`
  `m_numIncorrectTree`
  Weighted number of training examples currently misclassified by the subtree rooted at the node

  ### Fields inherited from class weka.classifiers.AbstractClassifier

  `BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LMTNode(ModelSelection modelSelection, int numBoostingIterations, boolean fastRegression, boolean errorOnProbabilities, int minNumInstances, double weightTrimBeta, boolean useAIC, NominalToBinary ntb, int numDecimalPlaces)`
  Constructor for logistic model tree node.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `assignIDs(int lastID)`
  Assigns unique IDs to all nodes in the tree
  `int`
  `assignLeafModelNumbers(int leafCounter)`
  Assigns numbers to the logistic regression models at the leaves of the tree
  `void`
  `buildClassifier(Instances data)`
  Method for building a logistic model tree (only called for the root node).
  `void`
  `buildTree(Instances data, SimpleLinearRegression[][] higherRegressions, double totalInstanceWeight, double higherNumParameters, Instances numericDataHeader)`
  Method for building the tree structure.
  `void`
  `calculateAlphas()`
  Updates the alpha field for all nodes.
  `double[]`
  `distributionForInstance(Instance instance)`
  Returns the class probabilities for an instance given by the logistic model tree.
  `String`
  `getModelParameters()`
  Returns a string describing the number of LogitBoost iterations performed at this node, the total number of LogitBoost iterations performed (including iterations at higher levels in the tree), and the number of training examples at this node.
  `Vector<LMTNode>`
  `getNodes()`
  Return a list of all inner nodes in the tree
  `void`
  `getNodes(Vector<LMTNode> nodeList)`
  Fills a list with all inner nodes in the tree
  `int`
  `getNumInnerNodes()`
  Method to count the number of inner nodes in the tree
  `int`
  `getNumLeaves()`
  Returns the number of leaves in the tree.
  `String`
  `getRevision()`
  Returns the revision string.
  `String`
  `graph()`
  Returns graph describing the tree.
  `boolean`
  `hasModels()`
  Returns true if the logistic regression model at this node has changed compared to the one at the parent node.
  `double[]`
  `modelDistributionForInstance(Instance instance)`
  Returns the class probabilities for an instance according to the logistic model at the node.
  `String`
  `modelsToString()`
  Returns a string describing the logistic regression function at the node.
  `int`
  `numLeaves()`
  Returns the number of leaves (normal count).
  `int`
  `numNodes()`
  Returns the number of nodes.
  `void`
  `prune(double alpha)`
  Prunes a logistic model tree using the CART pruning scheme, given a cost-complexity parameter alpha.
  `int`
  `prune(double[] alphas, double[] errors, Instances test)`
  Method for performing one fold in the cross-validation of the cost-complexity parameter.
  `String`
  `toString()`
  Returns a description of the logistic model tree (tree structure and logistic models)
  `void`
  `treeErrors()`
  Updates the numIncorrectTree field for all nodes.

  ### Methods inherited from class weka.classifiers.trees.lmt.LogisticBase

  `cleanup, getMaxIterations, getNumRegressions, getUseAIC, getUsedAttributes, getWeightTrimBeta, percentAttributesUsed, setHeuristicStop, setMaxIterations, setUseAIC, setWeightTrimBeta`

  ### Methods inherited from class weka.classifiers.AbstractClassifier

  `batchSizeTipText, classifyInstance, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getCapabilities, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, getOptions, implementsMoreEfficientBatchPrediction, listOptions, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces, setOptions`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### m_alpha

    public double m_alpha
    Alpha-value (for pruning) at the node

  - ### m_numIncorrectModel

    public double m_numIncorrectModel
    Weighted number of training examples currently misclassified by the logistic model at the node

  - ### m_numIncorrectTree

    public double m_numIncorrectTree
    Weighted number of training examples currently misclassified by the subtree rooted at the node

- ## Constructor Details

  - ### LMTNode

    public LMTNode(ModelSelection modelSelection, int numBoostingIterations, boolean fastRegression, boolean errorOnProbabilities, int minNumInstances, double weightTrimBeta, boolean useAIC, NominalToBinary ntb, int numDecimalPlaces)
    Constructor for logistic model tree node.
    Parameters:
      `modelSelection` - selection method for local splitting model
      `numBoostingIterations` - sets the numBoostingIterations parameter
      `fastRegression` - sets the fastRegression parameter
      `errorOnProbabilities` - Use error on probabilities for stopping criterion of LogitBoost?
      `minNumInstances` - minimum number of instances at which a node is considered for splitting

- ## Method Details

  - ### buildClassifier

    public void buildClassifier(Instances data) throws Exception
    Method for building a logistic model tree (only called for the root node). Grows an initial logistic model tree and prunes it back using the CART pruning scheme.
    Specified by:
      `buildClassifier` in interface `Classifier`
    Overrides:
      `buildClassifier` in class `LogisticBase`
    Parameters:
      `data` - the data to train with
    Throws:
      `Exception` - if something goes wrong

  - ### buildTree

    public void buildTree(Instances data, SimpleLinearRegression[][] higherRegressions, double totalInstanceWeight, double higherNumParameters, Instances numericDataHeader) throws Exception
    Method for building the tree structure. Builds a logistic model, splits the node and recursively builds tree for child nodes.
    Parameters:
      `data` - the training data passed on to this node
      `higherRegressions` - An array of regression functions produced by LogitBoost at higher levels in the tree. They represent a logistic regression model that is refined locally at this node.
      `totalInstanceWeight` - the total number of training examples
      `higherNumParameters` - effective number of parameters in the logistic regression model built in parent nodes
    Throws:
      `Exception` - if something goes wrong

  - ### prune

    public void prune(double alpha) throws Exception
    Prunes a logistic model tree using the CART pruning scheme, given a cost-complexity parameter alpha.
    Parameters:
      `alpha` - the cost-complexity measure
    Throws:
      `Exception` - if something goes wrong

  - ### prune

    public int prune(double[] alphas, double[] errors, Instances test) throws Exception
    Method for performing one fold in the cross-validation of the cost-complexity parameter. Generates a sequence of alpha-values with error estimates for the corresponding (partially pruned) trees, given the test set of that fold.
    Parameters:
      `alphas` - array to hold the generated alpha-values
      `errors` - array to hold the corresponding error estimates
      `test` - test set of that fold (to obtain error estimates)
    Throws:
      `Exception` - if something goes wrong

  - ### getNumInnerNodes

    public int getNumInnerNodes()
    Method to count the number of inner nodes in the tree
    Returns:
      the number of inner nodes

  - ### getNumLeaves

    public int getNumLeaves()
    Returns the number of leaves in the tree. Leaves are only counted if their logistic model has changed compared to the one of the parent node.
    Returns:
      the number of leaves

  - ### treeErrors

    public void treeErrors()
    Updates the numIncorrectTree field for all nodes. This is needed for calculating the alpha-values.

  - ### calculateAlphas

    public void calculateAlphas() throws Exception
    Updates the alpha field for all nodes.
    Throws:
      `Exception`

  - ### getNodes

    public Vector<LMTNode> getNodes()
    Return a list of all inner nodes in the tree
    Returns:
      the list of nodes

  - ### getNodes

    public void getNodes(Vector<LMTNode> nodeList)
    Fills a list with all inner nodes in the tree
    Parameters:
      `nodeList` - the list to be filled

  - ### hasModels

    public boolean hasModels()
    Returns true if the logistic regression model at this node has changed compared to the one at the parent node.
    Returns:
      whether it has changed

  - ### modelDistributionForInstance

    public double[] modelDistributionForInstance(Instance instance) throws Exception
    Returns the class probabilities for an instance according to the logistic model at the node.
    Parameters:
      `instance` - the instance
    Returns:
      the array of probabilities
    Throws:
      `Exception`

  - ### distributionForInstance

    public double[] distributionForInstance(Instance instance) throws Exception
    Returns the class probabilities for an instance given by the logistic model tree.
    Specified by:
      `distributionForInstance` in interface `Classifier`
    Overrides:
      `distributionForInstance` in class `LogisticBase`
    Parameters:
      `instance` - the instance
    Returns:
      the array of probabilities
    Throws:
      `Exception` - if distribution can't be computed successfully

  - ### numLeaves

    public int numLeaves()
    Returns the number of leaves (normal count).
    Returns:
      the number of leaves

  - ### numNodes

    public int numNodes()
    Returns the number of nodes.
    Returns:
      the number of nodes

  - ### toString

    public String toString()
    Returns a description of the logistic model tree (tree structure and logistic models)
    Overrides:
      `toString` in class `LogisticBase`
    Returns:
      describing string

  - ### getModelParameters

    public String getModelParameters()
    Returns a string describing the number of LogitBoost iterations performed at this node, the total number of LogitBoost iterations performed (including iterations at higher levels in the tree), and the number of training examples at this node.
    Returns:
      the describing string

  - ### assignIDs

    public int assignIDs(int lastID)
    Assigns unique IDs to all nodes in the tree

  - ### assignLeafModelNumbers

    public int assignLeafModelNumbers(int leafCounter)
    Assigns numbers to the logistic regression models at the leaves of the tree

  - ### modelsToString

    public String modelsToString()
    Returns a string describing the logistic regression function at the node.

  - ### graph

    public String graph() throws Exception
    Returns graph describing the tree.
    Throws:
      `Exception` - if something goes wrong

  - ### getRevision

    public String getRevision()
    Returns the revision string.
    Specified by:
      `getRevision` in interface `RevisionHandler`
    Overrides:
      `getRevision` in class `LogisticBase`
    Returns:
      the revision