Repository navigation
Return CV stopping diagnostics from cv.learner() and fix blank heatmaps after plot_objective() - #9
Merged
Merged
Conversation
In RStudio, the second CV heatmap in the advanced tutorial was blank once plot_objective() had run. plot_objective() no longer sets the margins with par(), so it uses the current margins. With very small margins the title and axis labels can be cut off. The help page and NEWS say so. New tests check that plot_objective() records no par() call and that a CV heatmap drawn before it is not damaged.
cv.learner() now returns cv_diagnostics, a data frame with one row per candidate and fold. It has the candidate number, the fold, the penalties, the number of updates, the stopping code, and whether the candidate was selected. The records are saved during CV, so no fold has to be refitted. If a candidate gives non-finite values, its remaining folds are skipped and their updates and stopping codes are NA. cv_learner_cpp() returns a list with the scores, the stopping codes and the update counts. The vignette and the example script read cv_diagnostics instead of recreating the folds and refitting them, and the multiple-source search is checked the same way. Section 4 uses cv_multi from Section 3, so its introduction and its check say to run the cross-validation in Section 3 first. The new tests compare the saved stopping codes and update counts with separate refits of every fold.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9 +/- ##
==========================================
+ Coverage 99.16% 99.18% +0.01%
==========================================
Files 7 7
Lines 599 610 +11
==========================================
+ Hits 594 605 +11
Misses 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
cv.learner() diagnostics
cv.learner()now returnscv_diagnostics, a data frame with one row per candidate and fold. The columns arecandidate,fold,lambda_1_row,lambda_1_col,lambda_2,updates,stop_codeandselected. The stopping codes mean the same as inlearner(): 1 for the stopping rule, 2 for the iteration limit, 3 for excessive growth or non-finite values. The records are saved during CV, so nothing is refitted.Example output of
cv_multi$cv_diagnostics, using the data and settings of the multiple-source example in the vignette. The vignette itself prints only the selected rows and the count of stopping codes:If a candidate gives non-finite values, its remaining folds are skipped and their
updatesandstop_codeareNA.cv_learner_cpp()now returns a list with the scores, the stopping codes and the update counts. The scores and the other elements of thecv.learner()result are unchanged.In the vignette, the section on CV fits used to recreate the folds with the same seed and refit them. It now reads
cv_diagnostics. It also shows the codes for all 18 fits in the multiple-source search: 14 meet the stopping rule and 4 reach the iteration limit, two of them in the selected candidate. Section 4 now usescv_multifrom Section 3, so its introduction and its check ask the reader to run the cross-validation in Section 3 first. The example script has the same changes, and its check at the top now looks forcv_diagnostics.plot_objective() and RStudio
In RStudio, the second CV heatmap in the tutorial was blank once
plot_objective()had run.plot_objective()no longer callspar(), so it uses the current margins instead of settingmar = c(5, 4.5, 4, 1.5). With the default margins the plot looks almost the same, but with very small margins the title and axis labels can be cut off. This is noted in the help page and in NEWS. I checked in RStudio and the second heatmap is drawn now. I do not know exactly why thepar()calls caused it. There are two new tests: one checks thatplot_objective()records nopar()call, and one checks that a CV heatmap drawn before it is not damaged.Checks
R CMD check --no-manualgives Status OK on macOS (R 4.6.1) with no warnings or notes. 737 expectations pass and the vignette builds. I also raninst/examples/advanced-learner.Rfrom top to bottom. I have not checked the PDF manual or other platforms. GitHub Actions should cover those.Please merge with a regular merge commit.