class_docstr: Experiment Class
  
  Parameters
  ----------
  eval_method: :obj:`<cornac.eval_methods.BaseMethod>`, required
      The evaluation method (e.g., RatioSplit).
  
  models: array of :obj:`<cornac.models.Recommender>`, required
      A collection of recommender models to evaluate, e.g., [C2PF, HPF, PMF].
  
  metrics: array of :obj:{`<cornac.metrics.RatingMetric>`, `<cornac.metrics.RankingMetric>`}, required
      A collection of metrics to use to evaluate the recommender models,         e.g., [NDCG, MRR, Recall].
  
  user_based: bool, optional, default: True
      This parameter is only useful if you are considering rating metrics. When True, first the average performance         for every user is computed, then the obtained values are averaged to return the final result.
      If `False`, results will be averaged over the number of ratings.
  
  show_validation: bool, optional, default: True 
      Whether to show the results on validation set (if exists).
  
  verbose: bool, optional, default: False
      Output running log/progress during model training and evaluation.
      If verbose is True, it will overwrite verbosity setting of evaluation method and models.
      
  save_dir: str, optional, default: None
      Path to a directory for storing trained models and logs. If None, 
      models will NOT be stored and logs will be saved in the current working directory.
  
  Attributes
  ----------
  result: array of :obj:`<cornac.experiment.result.Result>`, default: None
      This attribute contains the results per-model of your experiment 
      on the test set, initially it is set to None.
  
  val_result: array of :obj:`<cornac.experiment.result.Result>`, default: None
      This attribute contains the results per-model of your experiment
      on the validation set (if exists), initially it is set to None.
class_docstr_tok: ["Experiment","Class","Parameters","--","--","--","--","--","eval_method",":",":","obj",":","`","<","cornac.eval_methods.BaseMethod",">","`",",","required","The","evaluation","method","(","e.g.",",","RatioSplit",")",".","models",":","array","of",":","obj",":","`","<","cornac.models.Recommender",">","`",",","required","A","collection","of","recommender","models","to","evaluate",",","e.g.",",","[","C2PF",",","HPF",",","PMF","]",".","metrics",":","array","of",":","obj",":","{","`","<","cornac.metrics.RatingMetric",">","`",",","`","<","cornac.metrics.RankingMetric",">","`","}",",","required","A","collection","of","metrics","to","use","to","evaluate","the","recommender","models",",","e.g.",",","[","NDCG",",","MRR",",","Recall","]",".","user_based",":","bool",",","optional",",","default",":","True","This","parameter","is","only","useful","if","you","are","considering","rating","metrics",".","When","True",",","first","the","average","performance","for","every","user","is","computed",",","then","the","obtained","values","are","averaged","to","return","the","final","result",".","If","`","False","`",",","results","will","be","averaged","over","the","number","of","ratings",".","show_validation",":","bool",",","optional",",","default",":","True","Whether","to","show","the","results","on","validation","set","(","if","exists",")",".","verbose",":","bool",",","optional",",","default",":","False","Output","running","log\/progress","during","model","training","and","evaluation",".","If","verbose","is","True",",","it","will","overwrite","verbosity","setting","of","evaluation","method","and","models",".","save_dir",":","str",",","optional",",","default",":","None","Path","to","a","directory","for","storing","trained","models","and","logs",".","If","None",",","models","will","NOT","be","stored","and","logs","will","be","saved","in","the","current","working","directory",".","Attributes","--","--","--","--","--","result",":","array","of",":","obj",":","`","<","cornac.experiment.result.Result",">","`",",","default",":","None","This","attribute","contains","the","results","per-model","of","your","experiment","on","the","test","set",",","initially","it","is","set","to","None",".","val_result",":","array","of",":","obj",":","`","<","cornac.experiment.result.Result",">","`",",","default",":","None","This","attribute","contains","the","results","per-model","of","your","experiment","on","the","validation","set","(","if","exists",")",",","initially","it","is","set","to","None","."]
docstr: Run the Cornac experiment
docstr_tok: ["Run","the","Cornac","experiment"]
code: def run(self):
      """Run the Cornac experiment"""
      self._create_result()
  
      # overwrite verbosity setting of evaluation method and models
      # if Experiment verbose is True
      if self.verbose:
          self.eval_method.verbose = self.verbose
          for model in self.models:
              model.verbose = self.verbose
  
      for model in self.models:
          test_result, val_result = self.eval_method.evaluate(
              model=model,
              metrics=self.metrics,
              user_based=self.user_based,
              show_validation=self.show_validation,
          )
  
          self.result.append(test_result)
          if self.val_result is not None:
              self.val_result.append(val_result)
  
          if self.save_dir and (
              not isinstance(self.result, CVExperimentResult)
          ):
              model.save(self.save_dir)
  
      output = ""
      if self.val_result is not None:
          output += "\nVALIDATION:\n...\n{}".format(self.val_result)
      output += "\nTEST:\n...\n{}".format(self.result)
  
      print(output)
  
      timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S-%f")
      save_dir = "." if self.save_dir is None else self.save_dir
      output_file = os.path.join(
          save_dir, "CornacExp-{}.log".format(timestamp)
      )
      with open(output_file, "w") as f:
          f.write(output)
  
file_path: cornac/cornac/experiment/experiment.py
imports: import os
  from datetime import datetime
  from .result import ExperimentResult
  from .result import CVExperimentResult
  from ..metrics.rating import RatingMetric
  from ..metrics.ranking import RankingMetric
  from ..models.recommender import Recommender
label_desc: Use image node_id 5 for calling the Experiment obj's underlying member method code with example usage: obj.run() without return types