R/loadFullPredResults.R

Defines functions loadFullPredResults

loadFullPredResults = function(path) {
  # path = paste("results2", path, sep = "/")
  # init output
  resultDf = NULL

  datasets = list.dirs(path = path, full.names = F, recursive = F)

  for (dataset in datasets) {
    dataset_path = paste(path, dataset, sep = "/")

    # get classifier
    classifiers = list.dirs(path = dataset_path, full.names = F, recursive = F)

    for (classifier in classifiers) {
      # get iterations
      iterations = list.dirs(path = paste(dataset_path, classifier, sep = "/"), full.names = F, recursive = F)
      # print(iterations)

      for (iteration in iterations) {
        # build current path
        iteration_path = paste(dataset_path, classifier, iteration, sep = "/")

        aggr_file_path = list.files(iteration_path)
        agg_file = aggr_file_path[startsWith(aggr_file_path, "filter")]

        # browser()

        # check if done.txt exists
        if (length(agg_file) > 0) {
          # load result of iteration
          result_temp = readr::read_delim(
            paste(iteration_path, agg_file, sep = "/"),
            ";"
          )

          # if(!"fw.abs" %in% colnames(result_temp)) {
          #   next
          # }

          # set classifier
          result_temp$classifier = classifier
          result_temp$dataset = dataset

          result_temp = result_temp %>%
            dplyr::filter(ids == "full_predictor") %>%
            dplyr::group_by(ids, classifier, dataset) %>%
            dplyr::summarise(acc = 1 - mean(metric), feats = mean(numFeatures))

          # append to results
          if (is.null(resultDf)) {
            resultDf = result_temp
          }
          else {
            resultDf = rbind(resultDf, result_temp)
          }
        }
      }
    }
  }
  # browser()
  resultDf = resultDf  %>%
    dplyr::group_by(classifier, dataset) %>%
    dplyr::summarise(acc = mean(acc), feats = mean(feats))

  return(resultDf)
}
creil94/FeatureSelectionDashboard documentation built on Nov. 4, 2019, 9:17 a.m.