vigra - vigra::rf3 Namespace Reference

[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| vigra::rf3 Namespace Reference Machine Learning |

Random forest version 3. More...

## Classes
class | DepthStop
| Random forest 'maximum depth' stop criterion. More...
class | EntropyScore
| Functor that computes the entropy score. More...
class | GiniScore
| Functor that computes the gini score. More...
class | KolmogorovSmirnovScore
| Functor that computes the Kolmogorov-Smirnov score. More...
class | NodeComplexityStop
| Random forest 'node complexity' stop criterion. More...
class | NumInstancesStop
| Random forest 'number of datapoints' stop criterion. More...
class | OOBError
| Compute the out of bag error. More...
class | PurityStop
| Random forest 'node purity' stop criterion. More...
class | RandomForest
| Random forest version 3. More...
class | RandomForestOptions
| Options class for vigra::rf3::RandomForest version 3. More...
class | RFStopVisiting
| The default visitor node (= "do nothing"). More...
class | RFVisitorBase
| Base class from which all random forest visitors derive. More...
class | VariableImportance
| Compute the variable importance. More...
struct | VisitorCopy

## Functions
template<... >
void | random_forest (...)
| Train a vigra::rf3::RandomForest classifier. More...

## Detailed Description

Random forest version 3.

This namespace contains VIGRA's 3rd version of the random forest classification/regression algorithm. This version is much easier to customize than previous versions because it consequently separates algorithms from the forest representation, following the design of the LEMON graph library.

## Function Documentation

void vigra::rf3::random_forest | ( |  | ... | ) |

Train a vigra::rf3::RandomForest classifier.

This factory function constructs a vigra::rf3::RandomForest classifier and trains it for the given features and labels. They must be given as a matrix with shape `num_instances x num_features` and an array with length `num_instances` respectively. Most training options (such as number of trees in the forest, termination and split criteria, and number of threads for parallel training) are specified via an option object of type vigra::rf3::RandomForestOptions. Optional visitors are typically used to compute the out-of-bag error of the classifier (use vigra::rf3::OOBError) and estimate variable importance on the basis of the Gini gain (use vigra::rf3::VariableImportance). You can also provide a specific random number generator instance, which is especially useful when you want to enforce deterministic algorithm behavior during debugging.

Declaration:

namespace vigra { namespace rf3 {
template <typename FEATURES,
typename LABELS,
typename VISITOR = vigra::rf3::RFStopVisiting,
typename RANDENGINE = vigra::MersenneTwister>
vigra::rf3::RandomForest<FEATURES, LABELS>
random_forest(
FEATURES const & features,
LABELS const & labels,
vigra::rf3::RandomForestOptions const & options = vigra::rf3::RandomForestOptions(),
VISITOR visitor = vigra::rf3::RFStopVisiting(),
RANDENGINE & randengine = vigra::MersenneTwister::global()
);
}}

Usage:

#include <vigra/random_forest_3.hxx>
Namespace: vigra::rf3

using namespace vigra;
int num_instances = ...;
int num_features = ...;
MultiArray<2, double> train_features(Shape2(num_instances, num_features));
MultiArray<1, int> train_labels(Shape1(num_instances));
... // fill training data matrices
rf3::OOBError oob; // visitor to compute the out-of-bag error
auto rf = random_forest(train_features, train_labels,
rf3::RandomForestOptions().tree_count(100)
.features_per_node(rf3::RF_SQRT)
.n_threads(4)
rf3::create_visitor(oob));
std::cout << "Random forest training finished with out-of-bag error " << oob.oob_err_ << "\n";
int num_test_instances = ...;
MultiArray<2, double> test_features(Shape2(num_test_instances, num_features));
MultiArray<1, int> test_labels(Shape1(num_test_instances));
... // fill feature matrix for test data
rf.predict(test_features, test_labels);
for(int i=0; i<num_test_instances; ++i)
std::cerr << "Prediction for test instance " << i << ": " << test_labels(i) << "\n";

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.1 (Fri May 19 2017)