class_docstr: Next Item Recommendation Evaluation method
  
  Parameters
  ----------
  data: list, required
      Raw preference data in the tuple format [(user_id, sessions)].
  
  test_size: float, optional, default: 0.2
      The proportion of the test set,         if > 1 then it is treated as the size of the test set.
  
  val_size: float, optional, default: 0.0
      The proportion of the validation set,         if > 1 then it is treated as the size of the validation set.
  
  fmt: str, default: 'SIT'
      Format of the input data. Currently, we are supporting:
  
      'SIT': Session, Item, Timestamp
      'USIT': User, Session, Item, Timestamp
      'SITJson': Session, Item, Timestamp, Json
      'USITJson': User, Session, Item, Timestamp, Json
  
  seed: int, optional, default: None
      Random seed for reproducibility.
  
  mode: str, optional, default: 'last'
      Evaluation mode is either 'next' or 'last'.
      If 'last', only evaluate the last item.
      If 'next', evaluate every next item in the sequence,
  
  exclude_unknowns: bool, optional, default: True
      If `True`, unknown items will be ignored during model evaluation.
  
  verbose: bool, optional, default: False
      Output running log.
class_docstr_tok: ["Next","Item","Recommendation","Evaluation","method","Parameters","--","--","--","--","--","data",":","list",",","required","Raw","preference","data","in","the","tuple","format","[","(","user_id",",","sessions",")","]",".","test_size",":","float",",","optional",",","default",":","0.2","The","proportion","of","the","test","set",",","if",">","1","then","it","is","treated","as","the","size","of","the","test","set",".","val_size",":","float",",","optional",",","default",":","0.0","The","proportion","of","the","validation","set",",","if",">","1","then","it","is","treated","as","the","size","of","the","validation","set",".","fmt",":","str",",","default",":","'SIT'","Format","of","the","input","data",".","Currently",",","we","are","supporting",":","'SIT","'",":","Session",",","Item",",","Timestamp","'USIT","'",":","User",",","Session",",","Item",",","Timestamp","'SITJson","'",":","Session",",","Item",",","Timestamp",",","Json","'USITJson","'",":","User",",","Session",",","Item",",","Timestamp",",","Json","seed",":","int",",","optional",",","default",":","None","Random","seed","for","reproducibility",".","mode",":","str",",","optional",",","default",":","'last'","Evaluation","mode","is","either","'next","'","or","'last","'",".","If","'last","'",",","only","evaluate","the","last","item",".","If","'next","'",",","evaluate","every","next","item","in","the","sequence",",","exclude_unknowns",":","bool",",","optional",",","default",":","True","If","`","True","`",",","unknown","items","will","be","ignored","during","model","evaluation",".","verbose",":","bool",",","optional",",","default",":","False","Output","running","log","."]
docstr: Evaluate given models according to given metrics. Supposed to be called by Experiment.
  
  Parameters
  ----------
  model: :obj:`cornac.models.NextItemRecommender`
      NextItemRecommender model to be evaluated.
  
  metrics: :obj:`iterable`
      List of metrics.
  
  user_based: bool, required
      Evaluation strategy for the rating metrics. Whether results
      are averaging based on number of users or number of ratings.
  
  show_validation: bool, optional, default: True
      Whether to show the results on validation set (if exists).
  
  Returns
  -------
  res: :obj:`cornac.experiment.Result`
docstr_tok: ["Evaluate","given","models","according","to","given","metrics",".","Supposed","to","be","called","by","Experiment",".","Parameters","--","--","--","--","--","model",":",":","obj",":","`","cornac.models.NextItemRecommender","`","NextItemRecommender","model","to","be","evaluated",".","metrics",":",":","obj",":","`","iterable","`","List","of","metrics",".","user_based",":","bool",",","required","Evaluation","strategy","for","the","rating","metrics",".","Whether","results","are","averaging","based","on","number","of","users","or","number","of","ratings",".","show_validation",":","bool",",","optional",",","default",":","True","Whether","to","show","the","results","on","validation","set","(","if","exists",")",".","Returns","--","--","--","-","res",":",":","obj",":","`","cornac.experiment.Result","`"]
code: def evaluate(self, model, metrics, user_based, show_validation=True):
      """Evaluate given models according to given metrics. Supposed to be called by Experiment.
  
      Parameters
      ----------
      model: :obj:`cornac.models.NextItemRecommender`
          NextItemRecommender model to be evaluated.
  
      metrics: :obj:`iterable`
          List of metrics.
  
      user_based: bool, required
          Evaluation strategy for the rating metrics. Whether results
          are averaging based on number of users or number of ratings.
  
      show_validation: bool, optional, default: True
          Whether to show the results on validation set (if exists).
  
      Returns
      -------
      res: :obj:`cornac.experiment.Result`
      """
      if not isinstance(model, NextItemRecommender):
          raise ValueError(
              "model must be a NextItemRecommender but '%s' is provided"
              % type(model)
          )
  
      if self.train_set is None:
          raise ValueError("train_set is required but None!")
      if self.test_set is None:
          raise ValueError("test_set is required but None!")
  
      self._reset()
  
      ###########
      # FITTING #
      ###########
      if self.verbose:
          print("\n[{}] Training started!".format(model.name))
  
      start = time.time()
      model.fit(self.train_set, self.val_set)
      train_time = time.time() - start
  
      ##############
      # EVALUATION #
      ##############
      if self.verbose:
          print("\n[{}] Evaluation started!".format(model.name))
  
      rating_metrics, ranking_metrics = self.organize_metrics(metrics)
      if len(rating_metrics) > 0:
          warnings.warn(
              "NextItemEvaluation only supports ranking metrics. The given rating metrics {} will be ignored!".format(
                  [mt.name for mt in rating_metrics]
              )
          )
  
      start = time.time()
      model.transform(self.test_set)
      test_result = self.eval(
          model=model,
          train_set=self.train_set,
          test_set=self.test_set,
          val_set=self.val_set,
          exclude_unknowns=self.exclude_unknowns,
          ranking_metrics=ranking_metrics,
          user_based=user_based,
          mode=self.mode,
          verbose=self.verbose,
      )
      test_time = time.time() - start
      test_result.metric_avg_results["Train (s)"] = train_time
      test_result.metric_avg_results["Test (s)"] = test_time
  
      val_result = None
      if show_validation and self.val_set is not None:
          start = time.time()
          model.transform(self.val_set)
          val_result = self.eval(
              model=model,
              train_set=self.train_set,
              test_set=self.val_set,
              val_set=None,
              exclude_unknowns=self.exclude_unknowns,
              ranking_metrics=ranking_metrics,
              user_based=user_based,
              mode=self.mode,
              verbose=self.verbose,
          )
          val_time = time.time() - start
          val_result.metric_avg_results["Time (s)"] = val_time
  
      return test_result, val_result
  
file_path: cornac/cornac/eval_methods/next_item_evaluation.py
imports: import time
  import warnings
  from collections import OrderedDict, defaultdict
  import numpy
  from tqdm.auto import tqdm
  from ..data import SequentialDataset
  from ..experiment.result import Result
  from ..models import NextItemRecommender
  from .None import BaseMethod
label_desc: Use image node_id 4 for calling the NextItemEvaluation obj's underlying member method code with example usage: obj.evaluate(model, metrics, user_based, show_validation) and returns: test_result,  val_result