-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Stop cross-validation early if the parameters have high predicted test loss #915
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
692fdbb
Stop cross-validation early if the parameters have high predicted tes…
tveasey 1829c6d
Fix progress reporting for large numbers of features
tveasey 7f557e5
Docs
tveasey ed67d85
Improve comment
tveasey 4e1c097
Merge branch 'master' into early-stopping-cv
tveasey 01c5d45
Expand comment and rejig calculation of default number folds
tveasey 294e0b9
Factor out named constant
tveasey b6943e4
Expand comment explaining fold error estimation for early stopping
tveasey de99d29
Rejig slightly for readability
tveasey 87f7c6c
Fix limiting maximum number of folds
tveasey c4d89ed
Correct comment
tveasey 8873dac
Tweak comment
tveasey 1506d28
Merge branch 'master' into early-stopping-cv
tveasey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,10 @@ const double MIN_DOWNSAMPLE_LINE_SEARCH_RANGE{2.0}; | |
const double MAX_DOWNSAMPLE_LINE_SEARCH_RANGE{144.0}; | ||
const double MIN_DOWNSAMPLE_FACTOR_SCALE{0.3}; | ||
const double MAX_DOWNSAMPLE_FACTOR_SCALE{3.0}; | ||
const std::size_t MAX_NUMBER_FOLDS{5}; | ||
// This isn't a hard limit be we increase the number of default training folds | ||
// if the initial downsample fraction would be larger than this. | ||
const double MAX_DESIRED_INITIAL_DOWNSAMPLE_FRACTION{0.5}; | ||
const double MAX_NUMBER_FOLDS{5.0}; | ||
const std::size_t MAX_NUMBER_TREES{static_cast<std::size_t>(2.0 / MIN_ETA + 0.5)}; | ||
|
||
double computeEta(std::size_t numberRegressors) { | ||
|
@@ -250,20 +253,32 @@ void CBoostedTreeFactory::initializeNumberFolds(core::CDataFrame& frame) const { | |
} | ||
LOG_TRACE(<< "total number training rows = " << totalNumberTrainingRows); | ||
|
||
// We require at least twice the number of rows we'll sample in a bag per | ||
// fold if possible. In order to estimate this we use the number of input | ||
// features as a proxy for the number of features we'll actually use after | ||
// feature selection. | ||
double desiredTrainingFraction{(m_InitialDownsampleRowsPerFeature * | ||
static_cast<double>(frame.numberColumns() - 1)) / | ||
static_cast<double>(totalNumberTrainingRows)}; | ||
if (2.0 * desiredTrainingFraction >= 1.0 - 1.0 / static_cast<double>(MAX_NUMBER_FOLDS)) { | ||
m_TreeImpl->m_NumberFolds = MAX_NUMBER_FOLDS; | ||
} else { | ||
m_TreeImpl->m_NumberFolds = static_cast<std::size_t>( | ||
std::ceil(1.0 / (1.0 - 2.0 * desiredTrainingFraction))); | ||
} | ||
LOG_TRACE(<< "desired training fraction = " << desiredTrainingFraction | ||
// We want to choose the number of folds so we'll have enough training data | ||
// after leaving out one fold. We choose the initial downsample size based | ||
// on the same sort of criterion. So we require that leaving out one fold | ||
// shouldn't mean than we have fewer rows than constant * desired downsample | ||
// # rows if possible. We choose the constant to be two for no particularly | ||
// good reason except that: | ||
// 1. it isn't too large | ||
// 2. it still means we'll have plenty of variation between random bags. | ||
// | ||
// In order to estimate this we use the number of input features as a proxy | ||
// for the number of features we'll actually use after feature selection. | ||
// | ||
// So how does the following work: we'd like "c * f * # rows" training rows. | ||
// For k folds we'll have "(1 - 1 / k) * # rows" training rows. So we want | ||
// to find the smallest integer k s.t. c * f * # rows <= (1 - 1 / k) * # rows. | ||
// This gives k = ceil(1 / (1 - c * f)). However, we also upper bound this | ||
// by MAX_NUMBER_FOLDS. | ||
Comment on lines
+268
to
+272
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very nice explanation! |
||
|
||
double initialDownsampleFraction{(m_InitialDownsampleRowsPerFeature * | ||
static_cast<double>(frame.numberColumns() - 1)) / | ||
static_cast<double>(totalNumberTrainingRows)}; | ||
|
||
m_TreeImpl->m_NumberFolds = static_cast<std::size_t>( | ||
std::ceil(1.0 / std::max(1.0 - initialDownsampleFraction / MAX_DESIRED_INITIAL_DOWNSAMPLE_FRACTION, | ||
1.0 / MAX_NUMBER_FOLDS))); | ||
LOG_TRACE(<< "initial downsample fraction = " << initialDownsampleFraction | ||
<< " # folds = " << m_TreeImpl->m_NumberFolds); | ||
} else { | ||
m_TreeImpl->m_NumberFolds = *m_TreeImpl->m_NumberFoldsOverride; | ||
|
@@ -387,10 +402,10 @@ void CBoostedTreeFactory::initializeHyperparameters(core::CDataFrame& frame) { | |
} | ||
|
||
double numberFeatures{static_cast<double>(m_TreeImpl->m_Encoder->numberEncodedColumns())}; | ||
double downSampleFactor{m_InitialDownsampleRowsPerFeature * numberFeatures / | ||
double downsampleFactor{m_InitialDownsampleRowsPerFeature * numberFeatures / | ||
m_TreeImpl->m_TrainingRowMasks[0].manhattan()}; | ||
m_TreeImpl->m_DownsampleFactor = m_TreeImpl->m_DownsampleFactorOverride.value_or( | ||
CTools::truncate(downSampleFactor, 0.05, 0.5)); | ||
CTools::truncate(downsampleFactor, 0.05, 0.5)); | ||
|
||
m_TreeImpl->m_Regularization | ||
.depthPenaltyMultiplier( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, something wrong with this sentence.