void GNaiveBayes::autoTune(GMatrix& features, GMatrix& labels) { // Find the best ess value double bestEss = 0.0; double bestErr = 1e308; for(double i = 0.0; i < 8; i += 0.25) { m_equivalentSampleSize = i; double d = crossValidate(features, labels, 2); if(d < bestErr) { bestErr = d; bestEss = i; } else if(i >= 2.0) break; } // Set the best values m_equivalentSampleSize = bestEss; }
void GNaiveInstance::autoTune(GMatrix& features, GMatrix& labels) { // Find the best ess value size_t bestK = 0; double bestErr = 1e308; size_t cap = size_t(floor(sqrt(double(features.rows())))); for(size_t i = 2; i < cap; i = size_t(i * 1.5)) { m_nNeighbors = i; double d = crossValidate(features, labels, 2); if(d < bestErr) { bestErr = d; bestK = i; } else if(i >= 15) break; } // Set the best values m_nNeighbors = bestK; }