class_docstr: Graph modality
  
  Parameters
  ----------
  data: List[str], required
      A list encoding an adjacency matrix, of a user or an item graph, in the sparse triplet format,         e.g., data=[('user1', 'user4', 1.0)].
class_docstr_tok: ["Graph","modality","Parameters","--","--","--","--","--","data",":","List","[","str","]",",","required","A","list","encoding","an","adjacency","matrix",",","of","a","user","or","an","item","graph",",","in","the","sparse","triplet","format",",","e.g.",",","data=","[","(","'user1","'",",","'user4","'",",","1.0",")","]","."]
docstr: Build a KNN graph of a set of objects using similarities among there features.
  
  Parameters
  ----------
  features: 2d array, required
      A 2d Numpy array of features (object-by-features).
  k: int, optional, default: 5
      The number of nearest neighbors
  similarity: string, optional, default: "cosine"
      The similarity measure. At this time only the cosine is supported
  
  Returns
  -------
  graph_modality: :obj:`<cornac.data.GraphModality>`
      GraphModality object.
docstr_tok: ["Build","a","KNN","graph","of","a","set","of","objects","using","similarities","among","there","features",".","Parameters","--","--","--","--","--","features",":","2d","array",",","required","A","2d","Numpy","array","of","features","(","object-by-features",")",".","k",":","int",",","optional",",","default",":","5","The","number","of","nearest","neighbors","similarity",":","string",",","optional",",","default",":","``","cosine","''","The","similarity","measure",".","At","this","time","only","the","cosine","is","supported","Returns","--","--","--","-","graph_modality",":",":","obj",":","`","<","cornac.data.GraphModality",">","`","GraphModality","object","."]
code: def _build_knn(features, k=5, similarity="cosine", verbose=True):
      """Build a KNN graph of a set of objects using similarities among there features.
  
      Parameters
      ----------
      features: 2d array, required
          A 2d Numpy array of features (object-by-features).
      k: int, optional, default: 5
          The number of nearest neighbors
      similarity: string, optional, default: "cosine"
          The similarity measure. At this time only the cosine is supported
  
      Returns
      -------
      graph_modality: :obj:`<cornac.data.GraphModality>`
          GraphModality object.
      """
  
      # Some util variables
      n = len(features)
      N = np.zeros((n, k))
  
      if similarity == "cosine":
          # Normalize features to lie on a unit hypersphere
          l2_norm = np.linalg.norm(features, 2, axis=1, keepdims=True)
          features = features / (l2_norm + 1e-20)
  
      for i in trange(
          n, desc="Building KNN graph", disable=not verbose
      ):
          sim = features.dot(features[i])
          sim[i] = -np.inf  # ingore current idx
          k_largest_idx = np.argpartition(sim, -k)[-k:]
          N[i] = k_largest_idx
  
      return N
  
file_path: cornac/cornac/data/graph.py
imports: import scipy.sparse
  import numpy
  from tqdm.auto import trange
  from .None import FeatureModality
label_desc: Use image node_id 10 for calling the GraphModality obj's underlying member method code with example usage: obj._build_knn(features, k, similarity, verbose) and returns: N