RandomForestLearning Class |
Namespace: Accord.MachineLearning.DecisionTrees
[SerializableAttribute] public class RandomForestLearning : ParallelLearningBase, ISupervisedLearning<RandomForest, double[], int>
The RandomForestLearning type exposes the following members.
Name | Description | |
---|---|---|
RandomForestLearning |
Creates a new decision forest learning algorithm.
| |
RandomForestLearning(DecisionVariable) |
Creates a new decision forest learning algorithm.
| |
RandomForestLearning(OrderedDictionaryString, String) |
Creates a new decision forest learning algorithm.
| |
RandomForestLearning(RandomForest) |
Creates a new decision forest learning algorithm.
|
Name | Description | |
---|---|---|
Attributes |
Gets or sets the collection of attributes to
be processed by the induced decision tree.
| |
CoverageRatio |
Gets or sets the proportion of variables that
can be used at maximum by each tree in the decision
forest. Default is 1 (always use all variables).
| |
Join |
Gets or sets how many times the same variable can
enter a tree's decision path. Default is 100.
| |
NumberOfTrees |
Gets or sets the number of trees in the random forest.
| |
ParallelOptions |
Gets or sets the parallelization options for this algorithm.
(Inherited from ParallelLearningBase.) | |
SampleRatio |
Gets the proportion of samples used to train each
of the trees in the decision forest. Default is 0.632.
| |
Token |
Gets or sets a cancellation token that can be used
to cancel the algorithm while it is running.
(Inherited from ParallelLearningBase.) | |
Trees | Obsolete.
Gets or sets the number of trees in the random forest.
|
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Learn(Double, Int32, Double) |
Learns a model that can map the given inputs to the given outputs.
| |
Learn(Int32, Int32, Double) |
Learns a model that can map the given inputs to the given outputs.
| |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Run | Obsolete.
Runs the learning algorithm with the given data.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(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.) | |
ToT | 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.) |
This example shows the simplest way to induce a decision tree with continuous variables.
// Fix random seed for reproducibility Accord.Math.Random.Generator.Seed = 1; // In this example, we will process the famous Fisher's Iris dataset in // which the task is to classify weather the features of an Iris flower // belongs to an Iris setosa, an Iris versicolor, or an Iris virginica: // // - https://en.wikipedia.org/wiki/Iris_flower_data_set // // First, let's load the dataset: var iris = new DataSets.Iris(); double[][] inputs = iris.Instances; // flower features int[] outputs = iris.ClassLabels; // flower categories // Create the forest learning algorithm var teacher = new RandomForestLearning() { NumberOfTrees = 10, // use 10 trees in the forest }; // Finally, learn a random forest from data var forest = teacher.Learn(inputs, outputs); // We can estimate class labels using int[] predicted = forest.Decide(inputs); // And the classification error (0.0006) can be computed as double error = new ZeroOneLoss(outputs).Loss(forest.Decide(inputs));
The next example shows how to induce a decision tree with continuous variables using a codebook to manage how input variables should be encoded.
// Fix random seed for reproducibility Accord.Math.Random.Generator.Seed = 1; // This example uses the Nursery Database available from the University of // California Irvine repository of machine learning databases, available at // // http://archive.ics.uci.edu/ml/machine-learning-databases/nursery/nursery.names // // The description paragraph is listed as follows. // // Nursery Database was derived from a hierarchical decision model // originally developed to rank applications for nursery schools. It // was used during several years in 1980's when there was excessive // enrollment to these schools in Ljubljana, Slovenia, and the // rejected applications frequently needed an objective // explanation. The final decision depended on three subproblems: // occupation of parents and child's nursery, family structure and // financial standing, and social and health picture of the family. // The model was developed within expert system shell for decision // making DEX (M. Bohanec, V. Rajkovic: Expert system for decision // making. Sistemica 1(1), pp. 145-157, 1990.). // // Let's begin by loading the raw data. This string variable contains // the contents of the nursery.data file as a single, continuous text. // var nursery = new DataSets.Nursery(path: localPath); int[][] inputs = nursery.Instances; int[] outputs = nursery.ClassLabels; // Now, let's create the forest learning algorithm var teacher = new RandomForestLearning(nursery.VariableNames) { NumberOfTrees = 1, SampleRatio = 1.0 }; // Finally, learn a random forest from data var forest = teacher.Learn(inputs, outputs); // We can estimate class labels using int[] predicted = forest.Decide(inputs); // And the classification error (0) can be computed as double error = new ZeroOneLoss(outputs).Loss(forest.Decide(inputs));