class_docstr: Item-Based Nearest Neighbor.
  
  Parameters
  ----------
  name: string, default: 'ItemKNN'
      The name of the recommender model.
  
  k: int, optional, default: 20
      The number of nearest neighbors.
  
  similarity: str, optional, default: 'cosine'
      The similarity measurement. Supported types: ['cosine', 'pearson']
  
  mean_centered: bool, optional, default: False
      Whether values of the user-item rating matrix will be centered by the mean
      of their corresponding rows (mean rating of each user).
  
  weighting: str, optional, default: None
      The option for re-weighting the rating matrix. Supported types: ['idf', 'bm25'].
      If None, no weighting is applied.
  
  amplify: float, optional, default: 1.0
      Amplifying the influence on similarity weights.
  
  num_threads: int, optional, default: 0
      Number of parallel threads for training. If num_threads=0, all CPU cores will be utilized.
      If seed is not None, num_threads=1 to remove randomness from parallelization.
  
  seed: int, optional, default: None
      Random seed for weight initialization.
  
  References
  ----------
  * Sarwar, B., Karypis, G., Konstan, J., & Riedl, J. (2001, April). Item-based collaborative filtering recommendation algorithms. In Proceedings of the 10th international conference on World Wide Web (pp. 285-295).
  * Aggarwal, C. C. (2016). Recommender systems (Vol. 1). Cham: Springer International Publishing.
docstr: Fit the model to observations.
  
  Parameters
  ----------
  train_set: :obj:`cornac.data.Dataset`, required
      User-Item preference data as well as additional modalities.
  
  val_set: :obj:`cornac.data.Dataset`, optional, default: None
      User-Item preference data for model selection purposes (e.g., early stopping).
  
  Returns
  -------
  self : object
docstr_tok: ["Fit","the","model","to","observations",".","Parameters","--","--","--","--","--","train_set",":",":","obj",":","`","cornac.data.Dataset","`",",","required","User-Item","preference","data","as","well","as","additional","modalities",".","val_set",":",":","obj",":","`","cornac.data.Dataset","`",",","optional",",","default",":","None","User-Item","preference","data","for","model","selection","purposes","(","e.g.",",","early","stopping",")",".","Returns","--","--","--","-","self",":","object"]
code: def fit(self, train_set, val_set=None):
      """Fit the model to observations.
  
      Parameters
      ----------
      train_set: :obj:`cornac.data.Dataset`, required
          User-Item preference data as well as additional modalities.
  
      val_set: :obj:`cornac.data.Dataset`, optional, default: None
          User-Item preference data for model selection purposes (e.g., early stopping).
  
      Returns
      -------
      self : object
      """
      Recommender.fit(self, train_set, val_set)
  
      self.ui_mat = train_set.matrix.copy()
      self.mean_arr = np.zeros(self.ui_mat.shape[0])
      if self.min_rating != self.max_rating:  # explicit feedback
          self.ui_mat, self.mean_arr = _mean_centered(self.ui_mat)
  
      if self.mean_centered:
          weight_mat = self.ui_mat.copy()
      else:
          weight_mat = train_set.matrix.copy()
  
      if self.similarity == "pearson":  # centered by columns
          weight_mat, _ = _mean_centered(weight_mat.T.tocsr())
          weight_mat = weight_mat.T.tocsr()
  
      # re-weighting
      if self.weighting == "idf":
          weight_mat.data *= np.sqrt(_idf_weight(train_set.matrix))
      elif self.weighting == "bm25":
          weight_mat.data *= np.sqrt(_bm25_weight(train_set.matrix))
  
      weight_mat = weight_mat.T.tocsr()
      self.sim_mat = compute_similarity(
          weight_mat,
          k=self.k,
          num_threads=self.num_threads,
          verbose=self.verbose,
      )
      self.sim_mat = _amplify(self.sim_mat, self.amplify)
  
      return self
  
imports: import multiprocessing
  import numpy
  from scipy.sparse import csr_matrix, coo_matrix
  from ..recommender import Recommender
  from ...exception import ScoreException
  from ...utils import get_rng
  from ...utils.fast_sparse_funcs import inplace_csr_row_normalize_l2
  from .similarity import compute_similarity, compute_score, compute_score_single
label_desc: Use image node_id 2 for calling the ItemKNN obj's underlying member method code with example usage: obj.fit(train_set, val_set) and returns: self