13 #ifndef MLPACK_METHODS_HOEFFDING_TREES_GINI_INDEX_HPP 14 #define MLPACK_METHODS_HOEFFDING_TREES_GINI_INDEX_HPP 24 static double Evaluate(
const arma::Mat<size_t>& counts)
30 arma::vec splitCounts(counts.n_cols);
31 for (
size_t i = 0; i < counts.n_cols; ++i)
33 splitCounts[i] = arma::accu(counts.col(i));
34 numElem += splitCounts[i];
41 arma::Col<size_t> classCounts = arma::sum(counts, 1);
44 double impurity = 0.0;
45 for (
size_t i = 0; i < classCounts.n_elem; ++i)
47 const double f = ((double) classCounts[i] / (
double) numElem);
48 impurity += f * (1.0 - f);
53 for (
size_t i = 0; i < counts.n_cols; ++i)
55 if (splitCounts[i] > 0)
57 double splitImpurity = 0.0;
58 for (
size_t j = 0; j < counts.n_rows; ++j)
60 const double f = ((double) counts(j, i) / (double) splitCounts[i]);
61 splitImpurity += f * (1.0 - f);
64 impurity -= ((double) splitCounts[i] / (
double) numElem) *
77 static double Range(
const size_t numClasses)
82 return 1.0 - (1.0 / double(numClasses));
static double Range(const size_t numClasses)
Return the range of the Gini impurity for the given number of classes.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static double Evaluate(const arma::Mat< size_t > &counts)