Fixed implementation bug and normal distribution test

This commit is contained in:
Rishabh Garg
2021-07-12 10:05:01 +05:30
parent 8d3a7d7799
commit 0c265ccffe
2 changed files with 7 additions and 3 deletions
@@ -109,6 +109,8 @@ class MADGain
accWeights[0] += accWeights[1] + accWeights[2] + accWeights[3];
weightedMean[0] += weightedMean[1] + weightedMean[2] + weightedMean[3];
weightedMean[0] /= (double) (end - begin);
std::cout << "WeightedMean: " << weightedMean[0] << std::endl;
// Catch edge case: if there are no weights, the impurity is zero.
if (accWeights[0] == 0.0)
@@ -152,6 +154,8 @@ class MADGain
}
mean[0] += mean[1] + mean[2] + mean[3];
mean[0] /= (double) (end - begin);
std::cout << "Mean: " << mean[0] << std::endl;
for (size_t i = begin; i < end; ++i)
mad += std::abs(labels[i] - mean[0]);
+3 -3
View File
@@ -39,13 +39,13 @@ TEST_CASE("MADGainPerfectTest", "[DecisionTreeRegressionTest]")
}
/**
* Make sure that for a normal distribution of labels,
* MAD_gain = mean of absolute values of the distribution.
* Make sure that when mean of labels is zero, MAD_gain = mean of
* absolute values of the distribution.
*/
TEST_CASE("MADGainNormalTest", "[DecisionTreeRegressionTest")
{
arma::rowvec weights(10, arma::fill::ones);
arma::rowvec labels(10, arma::fill::randn); // Mean = 0.
arma::rowvec labels = { 1, 2, 3, 4, 5, -1, -2, -3, -4, -5 }; // Mean = 0.
// Theoretical gain.
double theoreticalGain = 0.0;