Skip to content

1/8 Tests and fixes to the cross-validation driver, train/predict and prepareData - #126

Merged
DarioS merged 3 commits into
develfrom
review/1-core-fixes
Oct 27, 2026
Merged

DarioS merged 3 commits into
develfrom
review/1-core-fixes

Conversation

@ellispatrick

@ellispatrick ellispatrick commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Part of a stack of 8 pull requests from the October 2026 audit of ClassifyR (AUDIT.md on branch audit-2026-10). Each part is based on the one before, so they need to be merged in order. Each one can be accepted, changed or rejected on its own merits. Draft PR #125 holds all eight together. Every part installs and passes its own tests.

Stack, merge in order: #126 tests and core fixes → #127 interface fixes → #128 metrics and plots → #129 pathways and criss-cross → #130 maintenance → #131 faster cross-validation (identical results) → #132 shared folds (changes results) → #133 release notes. The regression harness and timings are in SydneyBioX/ProjectClassifyR (private).

Summary

A testthat suite, and fixes to the cross-validation driver, train/predict and prepareData.

Why

The package had no tests, and the audit found settings that were silently ignored and code paths that fail on any input. In particular:

  • crossValidate ignored selectionMethod for MultiAssayExperiment and list input.
  • macOS was not recognised ("Darwin"), so nCores and the seed were ignored there.
  • Nested-CV tuning of classifier parameters always failed.
  • train() failed for more than one assay and for merge, prevalidation and PCA.

What changes

  • tests/testthat: smoke tests that run every classifier and selection keyword, plus a test for each fix below. XGB is added to the smoke tests in part 2, with its xgboost 3 fix.
  • crossValidate:
    • passes selectionMethod on for MultiAssayExperiment and list input;
    • chooses parallel settings by .Platform$OS.type;
    • applies extraParams with one helper (replacing two hand-copied loops with a copy-paste bug). A tuneParams list is now tuned rather than passed to the classifier as a setting, and tuning ranges without a tuning mode are an error instead of being ignored.
  • Tuning: tuning keeps the user's other training settings, which were replaced by the tuned values. Nested-CV tuning works (performances() → performance()).
  • train()/predict(): each model is fitted with runTest, as runTests fits its final model. This works for one or several assays and for merge, prevalidation and PCA. predict names new data as train does and gives each model the features it was trained with.
  • runTest: the MultiAssayExperiment method works (it used undefined variables). Prepared training data are used for survival outcomes as well.
  • Other fixes:
    • feature importance uses the cross-validation's performance type;
    • percentage splits use the outcome given (they used a global classes object if one existed);
    • nFeatures = 1 works;
    • prepareData's topNvariance (typo unqiue) and maxSimilarity (did nothing) work;
    • the kNN keyword works.
  • DESCRIPTION: the stale Packaged: 2014 field is removed.

Do results change?

No, for inputs that worked before. The regression harness (18 seeded scenarios covering every keyword and the protocol's four procedures) gave identical results to devel. Results change only where a setting used to be ignored, e.g. a non-default selectionMethod with MultiAssayExperiment input.

Evidence

70 tests pass.

How to review

  • R/crossValidate.R: .applyStageExtras, the guard in CV, train.DataFrame, predict.trainedByClassifyR.
  • R/runTest.R, R/utilities.R (.doTrain, samplesSplits), R/prepareData.R.
  • tests/testthat/test-core.R has one test per fix.

Questions

  • A vector of nFeatures is tuned by resubstitution. Classifiers that fit their training set perfectly then always pick the smallest value. This is kept as decided, and documented in part 6.
  • Balancing: ModellingParams() defaults to downsampling, but runTests never applies it. Left unchanged; which should it be?

🤖 Generated with Claude Code

https://claude.ai/code/session_01TfsjwkbDbHkX4kJZNe4ER4

ellispatrick and others added 3 commits October 9, 2026 19:18
…le Packaged field

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TfsjwkbDbHkX4kJZNe4ER4
- crossValidate passes selectionMethod on for MultiAssayExperiment and list input.
- Parallel parameters are chosen by .Platform.type, so macOS honours nCores and the seed.
- extraParams are applied to each stage by one helper; a tuneParams list is tuned rather than
  passed on as a setting, and tuning ranges without a tuning mode are an error.
- Tuning keeps the user's other training settings; nested CV tuning of classifier parameters works.
- train() fits each model with runTest, as runTests fits its final model, for one or several assays and
  for merge, prevalidation and PCA; predict() names new data as train() does and gives each model
  the features it was trained with.
- runTest: the MultiAssayExperiment method works; prepared training data is used for survival too.
- Feature importance uses the cross-validation's performance type.
- Percentage splits use the outcome given (and balance events for survival); nFeatures = 1 works.
- prepareData: topNvariance and maxSimilarity work; the clinical-features warning can fire.
- The kNN keyword works.
- Tests for each of these in tests/testthat/test-core.R.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TfsjwkbDbHkX4kJZNe4ER4

@DarioS DarioS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks out.

@DarioS
DarioS merged commit f2d2a41 into devel Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants