shark::RFClassifier< LabelType > Class Template Reference

Random Forest Classifier. More...

#include <shark/Models/Trees/RFClassifier.h>

+ Inheritance diagram for shark::RFClassifier< LabelType >:

Public Member Functions

std::string name () const
 From INameable: return the class name.
 
double OOBerror () const
 Returns the computed out-of-bag-error of the forest.
 
RealVector const & featureImportances () const
 Returns the computed feature importances of the forest.
 
UIntVector countAttributes () const
 Counts how often attributes are used.
 
void computeOOBerror (std::vector< std::vector< std::size_t > > const &oobIndices, LabeledData< RealVector, LabelType > const &data)
 Compute oob error, given an oob dataset.
 
void computeFeatureImportances (std::vector< std::vector< std::size_t > > const &oobIndices, LabeledData< RealVector, LabelType > const &data, random::rng_type &rng)
 
- Public Member Functions inherited from shark::Ensemble< CARTree< LabelType > >
void addModel (CARTree< LabelType > const &model, double weight=1.0)
 Adds a new model to the ensemble.
 
void clearModels ()
 Removes all models from the ensemble.
 
std::size_t numberOfModels () const
 Returns the number of models.
 
std::remove_pointer< CARTree< LabelType > >::type & model (std::size_t i)
 Returns a reference to the i-th model.
 
std::remove_pointer< CARTree< LabelType > >::type const & model (std::size_t i) const
 Returns a const reference to the i-th model.
 
double const & weight (std::size_t i) const
 Returns the weight of the i-th model.
 
double & weight (std::size_t i)
 Returns the weight of the i-th model.
 
double sumOfWeights () const
 Returns the total sum of weights used for averaging.
 

Detailed Description

template<class LabelType>
class shark::RFClassifier< LabelType >

Random Forest Classifier.

The Random Forest Classifier predicts a class label using the Random Forest algorithm as described in
Random Forests. Leo Breiman. Machine Learning, 1(45), pages 5-32. Springer, 2001.
It is an ensemble learner that uses multiple decision trees built using the CART methodology. The trees are created using bagging which allows the use the out-of-bag error estimates for an approximately unbiased estimate of the test-error as well as unbiased feature-importance estimates using feature permutation.

Definition at line 61 of file RFClassifier.h.

Member Function Documentation

◆ computeFeatureImportances()

template<class LabelType >
void shark::RFClassifier< LabelType >::computeFeatureImportances ( std::vector< std::vector< std::size_t > > const &  oobIndices,
LabeledData< RealVector, LabelType > const &  data,
random::rng_type &  rng 
)
inline

Compute feature importances, given an oob dataset

For each tree, extracts the out-of-bag-samples indicated by oobIndices. The feature importance is defined as the average change of loss (Squared loss or accuracy depending on label type) when the feature is permuted across the oob samples of a tree.

Definition at line 170 of file RFClassifier.h.

References shark::inputDimension(), shark::Ensemble< CARTree< LabelType > >::numberOfModels(), shark::subBatch(), shark::Ensemble< CARTree< LabelType > >::sumOfWeights(), and shark::Ensemble< CARTree< LabelType > >::weight().

Referenced by shark::RFTrainer< unsigned int >::train(), and shark::RFTrainer< RealVector >::train().

◆ computeOOBerror()

template<class LabelType >
void shark::RFClassifier< LabelType >::computeOOBerror ( std::vector< std::vector< std::size_t > > const &  oobIndices,
LabeledData< RealVector, LabelType > const &  data 
)
inline

Compute oob error, given an oob dataset.

Definition at line 157 of file RFClassifier.h.

References shark::LabeledData< InputT, LabelT >::numberOfElements().

Referenced by shark::RFTrainer< unsigned int >::train(), and shark::RFTrainer< RealVector >::train().

◆ countAttributes()

template<class LabelType >
UIntVector shark::RFClassifier< LabelType >::countAttributes ( ) const
inline

Counts how often attributes are used.

Definition at line 146 of file RFClassifier.h.

References shark::Ensemble< CARTree< LabelType > >::model(), and shark::Ensemble< CARTree< LabelType > >::numberOfModels().

◆ featureImportances()

template<class LabelType >
RealVector const & shark::RFClassifier< LabelType >::featureImportances ( ) const
inline

Returns the computed feature importances of the forest.

Definition at line 141 of file RFClassifier.h.

◆ name()

template<class LabelType >
std::string shark::RFClassifier< LabelType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::Ensemble< CARTree< LabelType > >.

Definition at line 131 of file RFClassifier.h.

◆ OOBerror()

template<class LabelType >
double shark::RFClassifier< LabelType >::OOBerror ( ) const
inline

Returns the computed out-of-bag-error of the forest.

Definition at line 136 of file RFClassifier.h.


The documentation for this class was generated from the following file: