Click or drag to resize
Accord.NET (logo)

ErrorBasedPruning Class

Error-based pruning.
Inheritance Hierarchy
SystemObject
  Accord.MachineLearning.DecisionTrees.PruningErrorBasedPruning

Namespace:  Accord.MachineLearning.DecisionTrees.Pruning
Assembly:  Accord.MachineLearning (in Accord.MachineLearning.dll) Version: 3.8.0
Syntax
public class ErrorBasedPruning
Request Example View Source

The ErrorBasedPruning type exposes the following members.

Constructors
  NameDescription
Public methodErrorBasedPruning
Initializes a new instance of the ErrorBasedPruning class.
Top
Properties
  NameDescription
Public propertyThreshold
Gets or sets the minimum allowed gain threshold to prune the tree. Default is 0.01.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRun
Computes one pass of the pruning algorithm.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

References:

  • Lior Rokach, Oded Maimon. The Data Mining and Knowledge Discovery Handbook, Chapter 9, Decision Trees. Springer, 2nd ed. 2010, XX, 1285 p. 40 illus. Available at: http://www.ise.bgu.ac.il/faculty/liorr/hbchap9.pdf .

Examples
// Suppose you have the following input and output data
// and would like to learn the relationship between the
// inputs and outputs by using a Decision Tree:

double[][] inputs = ...
int[] output = ...

// To prune a decision tree, we need to split your data into
// training and pruning groups. Let's say we have 100 samples,
// and would like to reserve 50 samples for training, and 50
// for pruning:

// Gather the first half for the training set
var trainingInputs = inputs.Submatrix(0, 49);
var trainingOutput = output.Submatrix(0, 49);

// Gather the second hand data for pruning
var pruningInputs = inputs.Submatrix(50, 99);
var pruningOutput = output.Submatrix(50, 99);


// Create the decision tree
DecisionTree tree = new DecisionTree( ... );

// Learn our tree using the training data
C45Learning c45 = new C45Learning(tree);
double error = c45.Run(trainingInputs, trainingOutput);


// Now we can attempt to prune the tree using the pruning groups
ErrorBasedPruning prune = new ErrorBasedPruning(tree, pruningInputs, pruningOutput);

// Gain threshold
prune.Threshold = 0.1;

double lastError;
double error = Double.PositiveInfinity;

do
{
    // Now we can start pruning the tree as 
    // long as the error doesn't increase

    lastError = error;
    error = prune.Run();

} while (error < lastError);
See Also