The key question for me is, if the pseudo code below implements so called nested cross validation:
ps: 2 hyperparameter configs
folds : 6 folds
-> 12 model evaluations
for p in ps:
for fold in folds :
model = train (fold.train-data, p)
prediction = predict(model,fold.test-data)
metric = calc-metric(prediction, fold.test-data)
metric-of-p = mean (metrics of all folds)
best-model = p which has best metric-of-p
Hi, Python ML libraries like scikit-learn take an OOP approach but R is quite a functional language so there might be some resources there that you can reference. R’s ‘tidymodels’ framework has the function nested_cv() for nested cross-validation. It’s implemented as a map of the inner CV function over the outer CV splits: