docstr: Cross Validation
  
  This strategy is responsible to divide the database in K folds, in which each fold contain a train and a test
  set. Its also responsible to run and evaluate the recommender results in each fold and calculate the mean and
  the standard deviation.
  
  Usage:
      >> rec = MostPopular(as_binary=True)
      >> CrossValidation(db, rec, fold_d, evaluation_in_fold_verbose=False).compute()
  
  :param input_file: Database file
  :type input_file: str
  
  :param recommender: Initialize the recommender algorithm. e.g.: MostPopular(as_binary=True)
  :type recommender: class
  
  :param dir_folds: Directory to write folds (train and test files)
  :type dir_folds: str
  
  :param k_folds: How much folds the strategy will divide
  :type k_folds: int, default 10
  
  :param header: Skip header line
  :type header: int, default None
  
  :param sep: Delimiter for input files
  :type sep: str, default '       '
  
  :param write_predictions: Write the recommender predictions in each fold
  :type write_predictions: bool, default False
  
  :param write_sep: Delimiter for output files
  :type write_sep: str, default ' '
  
  :param recommender_verbose: Print header of recommender in each fold
  :type recommender_verbose: bool, default False
  
  :param evaluation_in_fold_verbose: Print evaluation of recommender in each fold
  :type evaluation_in_fold_verbose: bool, default True
  
  :param metrics: List of evaluation metrics
  :type metrics: str, default None
  
  :param as_table: Print the evaluation results as table
  :type as_table: bool, default False
  
  :param table_sep: Delimiter for print results (only work with verbose=True and as_table=True)
  :type table_sep: str, default ' '
  
  :param del_folds: Delete folds after evaluation
  :type del_folds: bool, default False
  
  :param random_seed: Random seed
  :type random_seed: int, default None
code: def __init__(
      self,
      input_file,
      recommender,
      dir_folds,
      k_folds=10,
      header=None,
      sep="\t",
      write_predictions=False,
      write_sep="\t",
      recommender_verbose=False,
      evaluation_in_fold_verbose=True,
      metrics=None,
      as_table=False,
      table_sep="\t",
      del_folds=False,
      random_seed=None,
  ):
      """
      Cross Validation
  
      This strategy is responsible to divide the database in K folds, in which each fold contain a train and a test
      set. Its also responsible to run and evaluate the recommender results in each fold and calculate the mean and
      the standard deviation.
  
      Usage:
          >> rec = MostPopular(as_binary=True)
          >> CrossValidation(db, rec, fold_d, evaluation_in_fold_verbose=False).compute()
  
      :param input_file: Database file
      :type input_file: str
  
      :param recommender: Initialize the recommender algorithm. e.g.: MostPopular(as_binary=True)
      :type recommender: class
  
      :param dir_folds: Directory to write folds (train and test files)
      :type dir_folds: str
  
      :param k_folds: How much folds the strategy will divide
      :type k_folds: int, default 10
  
      :param header: Skip header line
      :type header: int, default None
  
      :param sep: Delimiter for input files
      :type sep: str, default '\t'
  
      :param write_predictions: Write the recommender predictions in each fold
      :type write_predictions: bool, default False
  
      :param write_sep: Delimiter for output files
      :type write_sep: str, default '\t'
  
      :param recommender_verbose: Print header of recommender in each fold
      :type recommender_verbose: bool, default False
  
      :param evaluation_in_fold_verbose: Print evaluation of recommender in each fold
      :type evaluation_in_fold_verbose: bool, default True
  
      :param metrics: List of evaluation metrics
      :type metrics: str, default None
  
      :param as_table: Print the evaluation results as table
      :type as_table: bool, default False
  
      :param table_sep: Delimiter for print results (only work with verbose=True and as_table=True)
      :type table_sep: str, default '\t'
  
      :param del_folds: Delete folds after evaluation
      :type del_folds: bool, default False
  
      :param random_seed: Random seed
      :type random_seed: int, default None
  
      """
  
      self.input_file = input_file
      self.recommender = recommender
      self.dir_folds = dir_folds
      self.k_folds = k_folds
      self.header = header
      self.sep = sep
      self.write_predictions = write_predictions
      self.write_sep = write_sep
      self.recommender_verbose = recommender_verbose
      self.evaluation_in_fold_verbose = evaluation_in_fold_verbose
      self.metrics = metrics
      self.as_table = as_table
      self.table_sep = table_sep
      self.del_folds = del_folds
      self.random_seed = random_seed
  
      # internal vars
      self.folds_results = defaultdict(list)
  
file_path: CaseRecommender/caserec/utils/cross_validation.py
imports: from collections import defaultdict
  import numpy
  import shutil
  from caserec.utils.split_database import SplitDatabase
label_desc: Use image node_id 1 to create a new CrossValidation object from inherited base classes: object with example: obj = CrossValidation(input_file, recommender, dir_folds, k_folds, header, sep, write_predictions, write_sep, recommender_verbose, evaluation_in_fold_verbose, metrics, as_table, table_sep, del_folds, random_seed)