class_docstr: Weighted Matrix Factorization.
  
  Parameters
  ----------
  name: string, default: 'WMF'
      The name of the recommender model.
  
  k: int, optional, default: 200
      The dimension of the latent factors.
  
  max_iter: int, optional, default: 100
      Maximum number of iterations or the number of epochs for SGD.
  
  learning_rate: float, optional, default: 0.001
      The learning rate for AdamOptimizer.
  
  lambda_u: float, optional, default: 0.01
      The regularization parameter for users.
  
  lambda_v: float, optional, default: 0.01
      The regularization parameter for items.
  
  a: float, optional, default: 1
      The confidence of observed ratings.
  
  b: float, optional, default: 0.01
      The confidence of unseen ratings.
  
  batch_size: int, optional, default: 128
      The batch size for SGD.
  
  trainable: boolean, optional, default: True
      When False, the model is not trained and Cornac assumes that the model already
      pre-trained (U and V are not None).
  
  init_params: dictionary, optional, default: None
      List of initial parameters, e.g., init_params = {'U':U, 'V':V}
  
      U: ndarray, shape (n_users,k)
          The user latent factors, optional initialization via init_params.
          
      V: ndarray, shape (n_items,k)
          The item latent factors, optional initialization via init_params.
  
  seed: int, optional, default: None
      Random seed for weight initialization.
  
  References
  ----------
  * Hu, Y., Koren, Y., & Volinsky, C. (2008, December). Collaborative filtering for implicit feedback datasets.     In 2008 Eighth IEEE International Conference on Data Mining (pp. 263-272).
  
  * Pan, R., Zhou, Y., Cao, B., Liu, N. N., Lukose, R., Scholz, M., & Yang, Q. (2008, December).     One-class collaborative filtering. In 2008 Eighth IEEE International Conference on Data Mining (pp. 502-511).
class_docstr_tok: ["Weighted","Matrix","Factorization",".","Parameters","--","--","--","--","--","name",":","string",",","default",":","'WMF'","The","name","of","the","recommender","model",".","k",":","int",",","optional",",","default",":","200","The","dimension","of","the","latent","factors",".","max_iter",":","int",",","optional",",","default",":","100","Maximum","number","of","iterations","or","the","number","of","epochs","for","SGD",".","learning_rate",":","float",",","optional",",","default",":","0.001","The","learning","rate","for","AdamOptimizer",".","lambda_u",":","float",",","optional",",","default",":","0.01","The","regularization","parameter","for","users",".","lambda_v",":","float",",","optional",",","default",":","0.01","The","regularization","parameter","for","items",".","a",":","float",",","optional",",","default",":","1","The","confidence","of","observed","ratings",".","b",":","float",",","optional",",","default",":","0.01","The","confidence","of","unseen","ratings",".","batch_size",":","int",",","optional",",","default",":","128","The","batch","size","for","SGD",".","trainable",":","boolean",",","optional",",","default",":","True","When","False",",","the","model","is","not","trained","and","Cornac","assumes","that","the","model","already","pre-trained","(","U","and","V","are","not","None",")",".","init_params",":","dictionary",",","optional",",","default",":","None","List","of","initial","parameters",",","e.g.",",","init_params","=","{","'","U","'",":","U",",","'","V","'",":","V","}","U",":","ndarray",",","shape","(","n_users",",","k",")","The","user","latent","factors",",","optional","initialization","via","init_params",".","V",":","ndarray",",","shape","(","n_items",",","k",")","The","item","latent","factors",",","optional","initialization","via","init_params",".","seed",":","int",",","optional",",","default",":","None","Random","seed","for","weight","initialization",".","References","--","--","--","--","--","*","Hu",",","Y.",",","Koren",",","Y.",",","&","Volinsky",",","C.","(","2008",",","December",")",".","Collaborative","filtering","for","implicit","feedback","datasets",".","In","2008","Eighth","IEEE","International","Conference","on","Data","Mining","(","pp",".","263-272",")",".","*","Pan",",","R.",",","Zhou",",","Y.",",","Cao",",","B.",",","Liu",",","N.","N.",",","Lukose",",","R.",",","Scholz",",","M.",",","&","Yang",",","Q",".","(","2008",",","December",")",".","One-class","collaborative","filtering",".","In","2008","Eighth","IEEE","International","Conference","on","Data","Mining","(","pp",".","502-511",")","."]
code: def _fit_cf(self, train_set):
      import tensorflow.compat.v1 as tf
      from .wmf import Model
  
      np.random.seed(self.seed)
      os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
      tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
  
      R = train_set.csc_matrix  # csc for efficient slicing over items
  
      # Build model
      graph = tf.Graph()
      with graph.as_default():
          tf.set_random_seed(self.seed)
          model = Model(
              n_users=self.num_users,
              n_items=self.num_items,
              k=self.k,
              lambda_u=self.lambda_u,
              lambda_v=self.lambda_v,
              lr=self.learning_rate,
              U=self.U,
              V=self.V,
          )
  
      # Training model
      config = tf.ConfigProto()
      config.gpu_options.allow_growth = True
      with tf.Session(config=config, graph=graph) as sess:
          sess.run(tf.global_variables_initializer())
  
          loop = trange(self.max_iter, disable=not self.verbose)
          for _ in loop:
              sum_loss = 0
              count = 0
              for i, batch_ids in enumerate(
                  train_set.item_iter(self.batch_size, shuffle=True)
              ):
                  batch_R = R[:, batch_ids]
                  batch_C = np.ones(batch_R.shape) * self.b
                  batch_C[batch_R.nonzero()] = self.a
                  feed_dict = {
                      model.ratings: batch_R.A,
                      model.C: batch_C,
                      model.item_ids: batch_ids,
                  }
                  _, _loss = sess.run(
                      [model.opt, model.loss], feed_dict
                  )  # train U, V
  
                  sum_loss += _loss
                  count += len(batch_ids)
                  if i % 10 == 0:
                      loop.set_postfix(loss=(sum_loss / count))
  
          self.U, self.V = sess.run([model.U, model.V])
  
      tf.reset_default_graph()
  
      if self.verbose:
          print("Learning completed!")
  
file_path: cornac/cornac/models/wmf/recom_wmf.py
imports: import os
  import numpy
  from tqdm.auto import trange
  from ..recommender import Recommender
  from ..recommender import ANNMixin, MEASURE_DOT
  from ...exception import ScoreException
  from ...utils import get_rng
  from ...utils.init_utils import xavier_uniform
label_desc: Use image node_id 4 for calling the WMF obj's underlying member method code with example usage: obj._fit_cf(train_set) without return types