class_docstr: Spherical k-means based recommender.
  
  Parameters
  ----------
  k: int, optional, default: 5
      The number of clusters.
  
  max_iter: int, optional, default: 100
      Maximum number of iterations.
  
  name: string, optional, default: 'Skmeans'
      The name of the recommender model.
  
  trainable: boolean, optional, default: True
      When False, the model is not trained and Cornac assumes that the model is already         trained. 
      
  tol : float, optional, default: 1e-6
      Relative tolerance with regards to skmeans' criterion to declare convergence.
      
  verbose: boolean, optional, default: False
      When True, some running logs are displayed.
  
  seed: int, optional, default: None
      Random seed for parameters initialization.
  
  init_par: numpy 1d array, optional, default: None
      The initial object parition, 1d array contaning the cluster label (int type starting from 0)         of each object (user). If par = None, then skmeans is initialized randomly.
    
  centroids: csc_matrix, shape (k,n_users)
      The maxtrix of cluster centroids.
  
  References
  ----------
  * Salah, Aghiles, Nicoleta Rogovschi, and Mohamed Nadif. "A dynamic collaborative filtering system     via a weighted clustering approach." Neurocomputing 175 (2016): 206-215.
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)
  
      X = train_set.matrix  # CSR matrix
  
      # Skmeans requires rows of X to have a unit L2 norm. We therefore need to make a copy of X as we should not modify the latter.
      X1 = X.copy()
      X1 = X1.multiply(
          sp.csc_matrix(
              1.0 / (np.sqrt(X1.multiply(X1).sum(1).A1) + 1e-20)
          ).T
      )
  
      if self.trainable:
          from .skmeans import skmeans
  
          res = skmeans(
              X1,
              k=self.k,
              max_iter=self.max_iter,
              tol=self.tol,
              verbose=self.verbose,
              seed=self.seed,
              init_par=getattr(self, "final_par", self.init_par),
          )
          self.centroids = res["centroids"]
          self.final_par = res["partition"]
      else:
          print(
              "%s is trained already (trainable = False)" % (self.name)
          )
  
      self.user_center_sim = (
          X1 * self.centroids.T
      )  # user-centroid cosine similarity matrix
      del X1
  
      return self
  
file_path: cornac/cornac/models/skm/recom_skmeans.py
imports: import numpy
  import scipy.sparse
  from ..recommender import Recommender
  from ...exception import ScoreException
label_desc: Use image node_id 2 for calling the SKMeans obj's underlying member method code with example usage: obj.fit(train_set, val_set) and returns: self