class_docstr: Training set contains preference matrix
  
  Parameters
  ----------
  num_users: int, required
      Number of users.
  
  num_items: int, required
      Number of items.
  
  uid_map: :obj:`OrderDict`, required
      The dictionary containing mapping from user original ids to mapped integer indices.
  
  iid_map: :obj:`OrderDict`, required
      The dictionary containing mapping from item original ids to mapped integer indices.
  
  uir_tuple: tuple, required
      Tuple of 3 numpy arrays (user_indices, item_indices, rating_values).
  
  timestamps: numpy.array, optional, default: None
      Array of timestamps corresponding to observations in `uir_tuple`.
  
  seed: int, optional, default: None
      Random seed for reproducing data sampling.
  
  Attributes
  ----------
  num_ratings: int
      Number of rating observations in the dataset.
  
  max_rating: float
      Maximum value among the rating observations.
  
  min_rating: float
      Minimum value among the rating observations.
  
  global_mean: float
      Average value over the rating observations.
  
  uir_tuple: tuple
      Tuple three numpy arrays (user_indices, item_indices, rating_values).
  
  timestamps: numpy.array
      Numpy array of timestamps corresponding to feedback in `uir_tuple`.
      This is only available when input data is in `UIRT` format.
class_docstr_tok: ["Training","set","contains","preference","matrix","Parameters","--","--","--","--","--","num_users",":","int",",","required","Number","of","users",".","num_items",":","int",",","required","Number","of","items",".","uid_map",":",":","obj",":","`","OrderDict","`",",","required","The","dictionary","containing","mapping","from","user","original","ids","to","mapped","integer","indices",".","iid_map",":",":","obj",":","`","OrderDict","`",",","required","The","dictionary","containing","mapping","from","item","original","ids","to","mapped","integer","indices",".","uir_tuple",":","tuple",",","required","Tuple","of","3","numpy","arrays","(","user_indices",",","item_indices",",","rating_values",")",".","timestamps",":","numpy.array",",","optional",",","default",":","None","Array","of","timestamps","corresponding","to","observations","in","`","uir_tuple","`",".","seed",":","int",",","optional",",","default",":","None","Random","seed","for","reproducing","data","sampling",".","Attributes","--","--","--","--","--","num_ratings",":","int","Number","of","rating","observations","in","the","dataset",".","max_rating",":","float","Maximum","value","among","the","rating","observations",".","min_rating",":","float","Minimum","value","among","the","rating","observations",".","global_mean",":","float","Average","value","over","the","rating","observations",".","uir_tuple",":","tuple","Tuple","three","numpy","arrays","(","user_indices",",","item_indices",",","rating_values",")",".","timestamps",":","numpy.array","Numpy","array","of","timestamps","corresponding","to","feedback","in","`","uir_tuple","`",".","This","is","only","available","when","input","data","is","in","`","UIRT","`","format","."]
docstr: Constructing Dataset from given data of specific format.
  
  Parameters
  ----------
  data: array-like, required
      Data in the form of triplets (user, item, rating) for UIR format,
      or quadruplets (user, item, rating, timestamps) for UIRT format.
  
  fmt: str, default: 'UIR'
      Format of the input data. Currently, we are supporting:
  
      'UIR': User, Item, Rating
      'UIRT': User, Item, Rating, Timestamp
  
  global_uid_map: :obj:`defaultdict`, optional, default: None
      The dictionary containing global mapping from original ids to mapped ids of users.
  
  global_iid_map: :obj:`defaultdict`, optional, default: None
      The dictionary containing global mapping from original ids to mapped ids of items.
  
  seed: int, optional, default: None
      Random seed for reproducing data sampling.
  
  exclude_unknowns: bool, default: False
      Ignore unknown users and items.
  
  Returns
  -------
  res: :obj:`<cornac.data.Dataset>`
      Dataset object.
docstr_tok: ["Constructing","Dataset","from","given","data","of","specific","format",".","Parameters","--","--","--","--","--","data",":","array-like",",","required","Data","in","the","form","of","triplets","(","user",",","item",",","rating",")","for","UIR","format",",","or","quadruplets","(","user",",","item",",","rating",",","timestamps",")","for","UIRT","format",".","fmt",":","str",",","default",":","'UIR'","Format","of","the","input","data",".","Currently",",","we","are","supporting",":","'UIR","'",":","User",",","Item",",","Rating","'UIRT","'",":","User",",","Item",",","Rating",",","Timestamp","global_uid_map",":",":","obj",":","`","defaultdict","`",",","optional",",","default",":","None","The","dictionary","containing","global","mapping","from","original","ids","to","mapped","ids","of","users",".","global_iid_map",":",":","obj",":","`","defaultdict","`",",","optional",",","default",":","None","The","dictionary","containing","global","mapping","from","original","ids","to","mapped","ids","of","items",".","seed",":","int",",","optional",",","default",":","None","Random","seed","for","reproducing","data","sampling",".","exclude_unknowns",":","bool",",","default",":","False","Ignore","unknown","users","and","items",".","Returns","--","--","--","-","res",":",":","obj",":","`","<","cornac.data.Dataset",">","`","Dataset","object","."]
code: def build(
      cls,
      data,
      fmt="UIR",
      global_uid_map=None,
      global_iid_map=None,
      seed=None,
      exclude_unknowns=False,
  ):
      """Constructing Dataset from given data of specific format.
  
      Parameters
      ----------
      data: array-like, required
          Data in the form of triplets (user, item, rating) for UIR format,
          or quadruplets (user, item, rating, timestamps) for UIRT format.
  
      fmt: str, default: 'UIR'
          Format of the input data. Currently, we are supporting:
  
          'UIR': User, Item, Rating
          'UIRT': User, Item, Rating, Timestamp
  
      global_uid_map: :obj:`defaultdict`, optional, default: None
          The dictionary containing global mapping from original ids to mapped ids of users.
  
      global_iid_map: :obj:`defaultdict`, optional, default: None
          The dictionary containing global mapping from original ids to mapped ids of items.
  
      seed: int, optional, default: None
          Random seed for reproducing data sampling.
  
      exclude_unknowns: bool, default: False
          Ignore unknown users and items.
  
      Returns
      -------
      res: :obj:`<cornac.data.Dataset>`
          Dataset object.
  
      """
      fmt = validate_format(fmt, ["UIR", "UIRT"])
  
      if global_uid_map is None:
          global_uid_map = OrderedDict()
      if global_iid_map is None:
          global_iid_map = OrderedDict()
  
      uid_map = OrderedDict()
      iid_map = OrderedDict()
  
      u_indices = []
      i_indices = []
      r_values = []
      valid_idx = []
  
      ui_set = set()  # avoid duplicate observations
      dup_count = 0
  
      for idx, (uid, iid, rating, *_) in enumerate(data):
          if exclude_unknowns and (
              uid not in global_uid_map or iid not in global_iid_map
          ):
              continue
  
          if (uid, iid) in ui_set:
              dup_count += 1
              continue
          ui_set.add((uid, iid))
  
          uid_map[uid] = global_uid_map.setdefault(
              uid, len(global_uid_map)
          )
          iid_map[iid] = global_iid_map.setdefault(
              iid, len(global_iid_map)
          )
  
          u_indices.append(uid_map[uid])
          i_indices.append(iid_map[iid])
          r_values.append(float(rating))
          valid_idx.append(idx)
  
      if dup_count > 0:
          warnings.warn(
              "%d duplicated observations are removed!" % dup_count
          )
  
      if len(ui_set) == 0:
          raise ValueError("data is empty after being filtered!")
  
      uir_tuple = (
          np.asarray(u_indices, dtype="int"),
          np.asarray(i_indices, dtype="int"),
          np.asarray(r_values, dtype="float"),
      )
  
      timestamps = (
          np.fromiter((int(data[i][3]) for i in valid_idx), dtype="int")
          if fmt == "UIRT"
          else None
      )
  
      dataset = cls(
          num_users=len(global_uid_map),
          num_items=len(global_iid_map),
          uid_map=global_uid_map,
          iid_map=global_iid_map,
          uir_tuple=uir_tuple,
          timestamps=timestamps,
          seed=seed,
      )
  
      return dataset
  
imports: import copy
  import os
  import pickle
  import warnings
  from collections import Counter, OrderedDict, defaultdict
  import numpy
  from scipy.sparse import csc_matrix, csr_matrix, dok_matrix
  from ..utils import estimate_batches, get_rng, validate_format
label_desc: Use image node_id 12 for calling the Dataset obj's underlying member method code with example usage: obj.build(cls, data, fmt, global_uid_map, global_iid_map, seed, exclude_unknowns) and returns: dataset