K fold cross validation model selection
Curated, evidence-grounded skill and software-tool collections for scientific AI agents, generated by the AgenticScienceBuilder
npx -y skills add HolobiomicsLab/asb-skill-collections --skill k-fold-cross-validation-model-selectionAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 14 stars14 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Use when when fitting a multi-block PLS discriminant model on multi-assay LC-MS metabolomics data and you need to determine the number of latent variables to retain without overfitting.
The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
7.1 KB, ~1.3k tokens by cl100k_base, as published. Nobody here has run it
k-fold-cross-validation-model-selection
Summary
Use k-fold cross-validation to estimate the optimal number of latent variables in a multi-block PLS model by iteratively training on k−1 folds and evaluating on the held-out fold, selecting the latent variable count where model performance plateaus. This prevents overfitting and provides a data-driven criterion for model complexity in multi-assay metabolomics integration.
When to use
When fitting a multi-block PLS discriminant model on multi-assay LC-MS metabolomics data and you need to determine the number of latent variables to retain without overfitting. Apply this skill after train-test splitting but before final model evaluation, to estimate the latent variable count that maximizes generalization performance (e.g., AUC) across the training cohort.
When NOT to use
- Latent variable count is already known or predetermined by prior domain knowledge or literature.
- Input is a small or sparse dataset where k-fold splitting leaves insufficient samples per fold for stable estimation.
- Response variable is continuous (use regression cross-validation metrics like RMSE instead) and linear model performance does not plateau meaningfully.
Inputs
- Multi-assay LC-MS intensity matrices (e.g., HPOS, LPOS, LNEG blocks) with assay-specific column name prefixes
- Binary or multiclass response vector (y) corresponding to samples in the intensity matrices
- Training subset of data (typically 80–90% of total samples)
Outputs
- Optimal number of latent variables (integer)
- Cross-validated performance scores (e.g., AUC) as a function of latent variable count
- Performance plateau identification (vector of metric values per LV)
How to apply
Split the training data into k folds (typically k=5). For each candidate number of latent variables, fit the MB-PLS model on k−1 training folds, evaluate on the held-out fold using a performance metric (AUC is recommended for classification), and record the metric. Aggregate scores across folds and identify the latent variable count where performance plateaus or ceases to improve meaningfully—use a plateau threshold (e.g., 0.01 improvement) to avoid retaining unnecessary latent variables that add no predictive gain. This cross-validated estimate guards against overfitting caused by tuning on the full training set. Refit the final model using the optimal latent variable count on all training data, then evaluate once on the independent test set.
Related tools
- mbpls (Implements the MB-PLS model fitting and the estimate_lv() method for k-fold cross-validation of latent variable count) — https://github.com/kopeckylukas/py-mamsi
- scikit-learn (Provides train_test_split for initial data partitioning and can support k-fold cross-validation utilities)
- MamsiPls (High-level wrapper that exposes the estimate_lv() method for automated k-fold cross-validation with AUC metric) — https://github.com/kopeckylukas/py-mamsi
Examples
mamsipls.estimate_lv([hpos_train, lpos_train, lneg_train], y_train, metric='auc')
Evaluation signals
- Cross-validated performance metric (AUC) reaches a plateau: successive increases in latent variables produce improvement < plateau_threshold (e.g., < 0.01 change in AUC).
- Selected latent variable count is lower than the maximum tested (indicating the model did not simply retain all candidates), preventing unnecessary complexity.
- Final model evaluated on independent test set shows performance (accuracy, recall, specificity, F1-score, AUC) consistent with cross-validation estimates, confirming no overfitting during latent variable selection.
- Cross-validation folds are balanced in size and sample composition; each fold contains representative samples from all outcome classes.
- Plateau threshold and number of folds are justified and reported explicitly in methods, ensuring reproducibility.
Limitations
- K-fold cross-validation is computationally expensive for very large datasets; larger k values (e.g., k=10) increase runtime proportionally.
- The choice of plateau_threshold is somewhat arbitrary; suboptimal thresholds may select too few or too many latent variables depending on the signal-to-noise ratio in the data.
- Small sample size relative to the number of features (common in LC-MS metabolomics) can lead to unstable cross-validation estimates; consider stratified k-fold to maintain outcome class balance.
- Performance metric choice (AUC, accuracy, etc.) influences the optimal latent variable count; different metrics may suggest different optima, requiring justification of metric selection.
Evidence
- [other] Estimate optimal number of latent variables using k-fold cross-validation (n_splits=5) with AUC metric via MamsiPls.estimate_lv(), identifying the model plateau threshold (plateau_threshold=0.01).: "Estimate optimal number of latent variables using k-fold cross-validation (n_splits=5) with AUC metric via MamsiPls.estimate_lv(), identifying the model plateau threshold (plateau_threshold=0.01)."
- [methods] For each candidate number of latent variables, fit the MB-PLS model on k−1 training folds, evaluate on the held-out fold using a performance metric (AUC is recommended for classification), and record the metric.: "estimate_lv([hpos_train, lpos_train, lneg_train], y_train, metric='auc')"
- [intro] The framework was tested on metabolomics phenotyping data with multi-assay LC-MS datasets: "the framework was tested on metabolomics phenotyping data, but it should be usable with other types of LC-MS data"
- [other] Refit MB-PLS with optimal latent variable count and evaluate on independent test set: "Refit MB-PLS with optimal latent variable count and evaluate on independent test set using MamsiPls.evaluate_class_model()"
- [readme] K-fold cross-validation prevents overfitting by providing independent evaluation folds: "You can install MAMSI from PyPI using pip:
pip install mamsi"
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.