RandomForest Class |
Namespace: Accord.MachineLearning.DecisionTrees
[SerializableAttribute] public class RandomForest : MulticlassClassifierBase, IParallel, ISupportsCancellation
The RandomForest type exposes the following members.
Name | Description | |
---|---|---|
RandomForest(DecisionTree) |
Creates a new random forest.
| |
RandomForest(Int32, Int32) |
Creates a new random forest.
| |
RandomForest(Int32, IListDecisionVariable, Int32) |
Creates a new random forest.
|
Name | Description | |
---|---|---|
Classes | Obsolete.
Gets the number of classes that can be recognized
by this random forest.
| |
NumberOfClasses |
Gets the number of classes expected and recognized by the classifier.
(Inherited from ClassifierBaseTInput, TClasses.) | |
NumberOfInputs |
Gets the number of inputs accepted by the model.
(Inherited from TransformBaseTInput, TOutput.) | |
NumberOfOutputs |
Gets the number of outputs generated by the model.
(Inherited from TransformBaseTInput, TOutput.) | |
ParallelOptions |
Gets or sets the parallelization options for this algorithm.
| |
Token |
Gets or sets a cancellation token that can be used
to cancel the algorithm while it is running.
| |
Trees |
Gets the trees in the random forest.
|
Name | Description | |
---|---|---|
Compute | Obsolete.
Computes the decision output for a given input vector.
| |
Decide(TInput) |
Computes class-label decisions for a given set of input vectors.
(Inherited from ClassifierBaseTInput, TClasses.) | |
Decide(Int32) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Double) |
Computes a class-label decision for a given input.
(Overrides ClassifierBaseTInput, TClassesDecide(TInput).) | |
Decide(TInput, TClasses) |
Computes a class-label decision for a given input.
(Inherited from ClassifierBaseTInput, TClasses.) | |
Decide(Int32, Boolean) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32, Double) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32, Int32) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32, Boolean) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32, Double) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32, Double) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32, Int32) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Int32, Int32) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Boolean) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Double) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Int32) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Boolean) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Double) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Double) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Int32) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(Single, Int32) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBase.) | |
Decide(TInput, Boolean) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBaseTInput.) | |
Decide(TInput, Double) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBaseTInput.) | |
Decide(TInput, Int32) |
Computes class-label decisions for the given input.
(Inherited from MulticlassClassifierBaseTInput.) | |
Decide(TInput, Double) |
Computes a class-label decision for a given input.
(Inherited from MulticlassClassifierBaseTInput.) | |
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.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnDeserializingMethod |
Called when the object is being deserialized.
| |
ToMultilabel |
Views this instance as a multi-label classifier,
giving access to more advanced methods, such as the prediction
of one-hot vectors.
(Inherited from MulticlassClassifierBaseTInput.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
Transform(TInput) |
Applies the transformation to an input, producing an associated output.
(Inherited from ClassifierBaseTInput, TClasses.) | |
Transform(Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(TInput) |
Applies the transformation to a set of input vectors,
producing an associated set of output vectors.
(Inherited from TransformBaseTInput, TOutput.) | |
Transform(TInput, TClasses) |
Applies the transformation to an input, producing an associated output.
(Inherited from ClassifierBaseTInput, TClasses.) | |
Transform(Int32, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Int32, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Int32, Boolean) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Int32, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Int32, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Int32, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Int32, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Boolean) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Boolean) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(Single, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBase.) | |
Transform(TInput, Boolean) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBaseTInput.) | |
Transform(TInput, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBaseTInput.) | |
Transform(TInput, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBaseTInput.) | |
Transform(TInput, Boolean) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBaseTInput.) | |
Transform(TInput, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBaseTInput.) | |
Transform(TInput, Double) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBaseTInput.) | |
Transform(TInput, Int32) |
Applies the transformation to an input, producing an associated output.
(Inherited from MulticlassClassifierBaseTInput.) |
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.) |
Represents a random forest of DecisionTrees. For sample usage and example of learning, please see the documentation page for RandomForestLearning.
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));