weka.classifiers.m5
Class Node

java.lang.Object
  |
  +--weka.classifiers.m5.Node
All Implemented Interfaces:
Serializable

public final class Node
extends Object
implements Serializable

Class for handing a node in the tree or the subtree under this node

Version:
$Revision: 1.5 $
Author:
Yong Wang (yongwang@cs.waikato.ac.nz)
See Also:
Serialized Form

Constructor Summary
Node(Instances inst, Node up)
          Constructs a new node
Node(Instances inst, Node up, Options options)
          Constructs the root of a tree
 
Method Summary
 Node copy(Node up)
          Makes a copy of the tree under this node
 Errors errors(Instances inst, boolean smooth)
          Evaluates a tree
 double factor(int n, int v, double pruningFactor)
          Calculates a multiplication factor used at this node
 String formulaeToString(boolean smooth)
          Converts all the linear models at the leaves under the node to a string
 void function()
          Finds the appropriate order of the unsmoothed linear model at this node
 void leafNode()
          Sets the node to a leaf
 int leafNum(Instance instance)
          Detects which leaf a instance falls into
 Measures measures(Instances inst, boolean smooth)
          Computes performance measures of a tree
 String measuresToString(Measures[] measures, Instances inst, int lmNo, int verbosity, String str)
          Converts the performance measures into a string
 int numberOfLinearModels()
          Counts the number of linear models in the tree.
 int numLeaves(int leafCounter)
          Sets the leaves' numbers
 double predict(Instance instance, boolean smooth)
          Predicts the class value of an instance by the tree
 String predictionsToString(Instances inst, int lmNo, boolean smooth)
          Converts the predictions by the tree under this node to a string
 void prune()
          Prunes the model tree
 void regression(Function function)
          Computes the coefficients of a linear model using the instances at this node
 String singleNodeToString()
          Converts the information stored at this node to a string
 void smoothen()
          Smoothens all unsmoothed formulae at the tree leaves under this node.
 void smoothenFormula(Node current)
          Recursively smoothens the unsmoothed linear model at this node with the unsmoothed linear models at the nodes above this
 void split(Instances inst)
          Splits the node recursively, unless there are few instances or instances have similar values of the class attribute
 String treeToString(int treeLevel, double deviation)
          Converts the tree under this node to a string
 Measures[] validation(Instances inst)
          Computes performance measures for both unsmoothed and smoothed models
 void valueNode()
          Takes a constant value as the function at the node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Node

public Node(Instances inst,
            Node up)
Constructs a new node

Parameters:
inst - instances
up - the parent node

Node

public Node(Instances inst,
            Node up,
            Options options)
Constructs the root of a tree

Parameters:
inst - instances
up - the parent node
options - the options
Method Detail

singleNodeToString

public final String singleNodeToString()
                                throws Exception
Converts the information stored at this node to a string

Returns:
the converted string
Throws:
Exception - if something goes wrong

treeToString

public final String treeToString(int treeLevel,
                                 double deviation)
Converts the tree under this node to a string

Parameters:
treeLevel - the depth of this node; the root of a tree should have treeLevel = 0
deviation - the global deviation of the class column, used for evaluating relative errors
Returns:
the converted string

numberOfLinearModels

public final int numberOfLinearModels()
Counts the number of linear models in the tree.


formulaeToString

public final String formulaeToString(boolean smooth)
                              throws Exception
Converts all the linear models at the leaves under the node to a string

Parameters:
smooth - either the smoothed models if true, otherwise the unsmoothed are converted
Returns:
the converted string
Throws:
Exception - if something goes wrong

numLeaves

public final int numLeaves(int leafCounter)
Sets the leaves' numbers

Parameters:
leafCounter - the number of leaves counted
Returns:
the number of the total leaves under the node

split

public final void split(Instances inst)
                 throws Exception
Splits the node recursively, unless there are few instances or instances have similar values of the class attribute

Parameters:
inst - instances
Throws:
Exception - if something goes wrong

leafNode

public final void leafNode()
                    throws Exception
Sets the node to a leaf

Throws:
Exception - if something goes wrong

valueNode

public final void valueNode()
                     throws Exception
Takes a constant value as the function at the node

Throws:
Exception - if something goes wrong

prune

public final void prune()
                 throws Exception
Prunes the model tree

Throws:
Exception - if something goes wrong

regression

public final void regression(Function function)
Computes the coefficients of a linear model using the instances at this node

Parameters:
function - the linear model containing the index of the attributes; coefficients are to be computed

function

public final void function()
                    throws Exception
Finds the appropriate order of the unsmoothed linear model at this node

Throws:
Exception - if something goes wrong

factor

public final double factor(int n,
                           int v,
                           double pruningFactor)
Calculates a multiplication factor used at this node

Parameters:
n - the number of instances
v - the number of the coefficients
pruningFactor - the pruning factor
Returns:
multiplication factor

smoothen

public final void smoothen()
Smoothens all unsmoothed formulae at the tree leaves under this node.


smoothenFormula

public final void smoothenFormula(Node current)
Recursively smoothens the unsmoothed linear model at this node with the unsmoothed linear models at the nodes above this

Parameters:
current - the unsmoothed linear model at the up node of the 'current' will be used for smoothening

predictionsToString

public final String predictionsToString(Instances inst,
                                        int lmNo,
                                        boolean smooth)
                                 throws Exception
Converts the predictions by the tree under this node to a string

Parameters:
smooth - =ture using the smoothed models; otherwise, the unsmoothed
Returns:
the converted string
Throws:
Exception - if something goes wrong

leafNum

public final int leafNum(Instance instance)
Detects which leaf a instance falls into

Returns:
the leaf no.

predict

public final double predict(Instance instance,
                            boolean smooth)
Predicts the class value of an instance by the tree

Parameters:
smooth - =true, uses the smoothed model; otherwise uses the unsmoothed
Returns:
the predicted value

errors

public final Errors errors(Instances inst,
                           boolean smooth)
                    throws Exception
Evaluates a tree

Parameters:
inst - instances
smooth - =true, evaluates the smoothed models; =false, evaluats the unsmoothed models
Returns:
the evaluation results
Throws:
Exception - if something goes wrong

measures

public final Measures measures(Instances inst,
                               boolean smooth)
                        throws Exception
Computes performance measures of a tree

Parameters:
inst - instances
smooth - =true uses the smoothed models; otherwise uses the unsmoothed models
Returns:
the performance measures
Throws:
Exception - if something goes wrong

validation

public final Measures[] validation(Instances inst)
                            throws Exception
Computes performance measures for both unsmoothed and smoothed models

Parameters:
inst - instances
Throws:
Exception - if something goes wrong

copy

public final Node copy(Node up)
                throws Exception
Makes a copy of the tree under this node

Parameters:
up - the parant node of the new node
Returns:
a copy of the tree under this node
Throws:
Exception - if something goes wrong

measuresToString

public final String measuresToString(Measures[] measures,
                                     Instances inst,
                                     int lmNo,
                                     int verbosity,
                                     String str)
                              throws Exception
Converts the performance measures into a string

Parameters:
inst - the instances
lmNo - also converts the predictions by all linear models if lmNo=0, or one linear model spedified by lmNo.
verbosity - the verbosity level
str - the type of evaluation, one of "t" for training, "T" for testing, "f" for fold training, "F" for fold testing, "x" for cross-validation
Returns:
the converted string
Throws:
Exception - if something goes wrong