- quality = NULL,
- run_res = NULL,
- get_testIndices = function(CV, v, n, shuffle_inds) {
- if (CV$type == "vfold") {
- first_index = round((v-1) * n / CV$V) + 1
- last_index = round(v * n / CV$V)
- test_indices = first_index:last_index
- if (CV$shuffle)
- test_indices <- shuffle_inds[test_indices]
- }
- else
- test_indices = sample(n, round(n * CV$test_size))
- test_indices
- },
- get_modelPerf = function(test_indices, p=0) {
- getOnePerf <- function(p) {
- model_pred <- private$gmodel$get(dataHO, targetHO, p)
- prediction <- model_pred(testX)
- perf <- private$quality(prediction, testY)
- list(model=model_pred, perf=perf)
- }
- dataHO <- private$data[-test_indices,]
- testX <- private$data[test_indices,]
- targetHO <- private$target[-test_indices]
- testY <- private$target[test_indices]
- # R will cast 1-dim matrices into vectors:
- if (!is.matrix(dataHO) && !is.data.frame(dataHO))
- dataHO <- as.matrix(dataHO)
- if (!is.matrix(testX) && !is.data.frame(testX))
- testX <- as.matrix(testX)
- if (p >= 1)
- # Standard CV: one model at a time
- return (getOnePerf(p)$perf)
- # Agghoo: loop on all models
- best_model = NULL
- best_perf <- -1
- for (p in 1:private$gmodel$nmodels) {
- model_perf <- getOnePerf(p)
- if (model_perf$perf > best_perf) {
- # TODO: if ex-aequos: models list + choose at random
- best_model <- model_perf$model
- best_perf <- model_perf$perf
- }
- }
- list(model=best_model, perf=best_perf)
- }