def spectral_clustering(affinity, n_clusters=8, n_components=None, eigen_solver=None, random_state=None, n_init=10, eigen_tol=0.0, assign_labels='kmeans'):
 if (assign_labels not in ('kmeans', 'discretize')):
  raise ValueError(("The 'assign_labels' parameter should be 'kmeans' or 'discretize', but '%s' was given" % assign_labels))
 random_state = check_random_state(random_state)
 n_components = (n_clusters if (n_components is None) else n_components)
 maps = spectral_embedding(affinity, n_components=n_components, eigen_solver=eigen_solver, random_state=random_state, eigen_tol=eigen_tol, drop_first=False)
 if (assign_labels == 'kmeans'):
  (_, labels, _) = k_means(maps, n_clusters, random_state=random_state, n_init=n_init)
 else:
  labels = discretize(maps, random_state=random_state)
 return labels

def spectral_clustering ( affinity , n_clusters = 8 , n_components = None , eigen_solver = None , random_state = None , n_init = 10 , eigen_tol = 0.0 , assign_labels = 'kmeans' ) : if ( assign_labels not in ( 'kmeans' , 'discretize' ) ) : raise ValueError ( ( "The 'assign_labels' parameter should be 'kmeans' or 'discretize', but '%s' was given" % assign_labels ) ) random_state = check_random_state ( random_state ) n_components = ( n_clusters if ( n_components is None ) else n_components ) maps = spectral_embedding ( affinity , n_components = n_components , eigen_solver = eigen_solver , random_state = random_state , eigen_tol = eigen_tol , drop_first = False ) if ( assign_labels == 'kmeans' ) : ( _ , labels , _ ) = k_means ( maps , n_clusters , random_state = random_state , n_init = n_init ) else : labels = discretize ( maps , random_state = random_state ) return labels
apply clustering to a projection to the normalized laplacian .