code: def spectral_clustering_sb(
      affinity,
      n_clusters=8,
      n_components=None,
      random_state=None,
      n_init=10,
  ):
      """Performs spectral clustering.
  
      Arguments
      ---------
      affinity : matrix
          Affinity matrix.
      n_clusters : int
          Number of clusters for kmeans.
      n_components : int
          Number of components to retain while estimating spectral embeddings.
      random_state : int
          A pseudo random number generator used by kmeans.
       n_init : int
          Number of time the k-means algorithm will be run with different centroid seeds.
  
      Returns
      -------
      labels : array
          Cluster label for each sample.
  
      Example
      -------
      >>> import numpy as np
      >>> from speechbrain.processing import diarization as diar
      >>> affinity = np.array([[1, 1, 1, 0.5, 0, 0, 0, 0, 0, 0.5],
      ... [1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
      ... [1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
      ... [0.5, 0, 0, 1, 1, 1, 0, 0, 0, 0],
      ... [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
      ... [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
      ... [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
      ... [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
      ... [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
      ... [0.5, 0, 0, 0, 0, 0, 1, 1, 1, 1]])
      >>> labs = diar.spectral_clustering_sb(affinity, 3)
      >>> # print (labs) # [2 2 2 1 1 1 0 0 0 0]
      """
  
      random_state = _check_random_state(random_state)
      n_components = (
          n_clusters if n_components is None else n_components
      )
  
      maps = spectral_embedding_sb(
          affinity,
          n_components=n_components,
          drop_first=False,
      )
  
      _, labels, _ = k_means(
          maps, n_clusters, random_state=random_state, n_init=n_init
      )
  
      return labels
  
imports: import csv
  import numbers
  import warnings
  import scipy
  import pytest
  import numpy
  from scipy import sparse
  from scipy.sparse.linalg import eigsh
  from scipy.sparse.csgraph import connected_components
  from scipy.sparse.csgraph import laplacian
label_desc: Use image node_id 15 for calling a global function with example usage: spectral_clustering_sb(affinity, n_clusters, n_components, random_state, n_init) and returns: labels