code: def clustering(X, algorithm, n_clusters):
      # normalize dataset for easier parameter selection
      X = StandardScaler().fit_transform(X)
  
      # estimate bandwidth for mean shift
      bandwidth = cluster.estimate_bandwidth(X, quantile=0.3)
  
      # connectivity matrix for structured Ward
      connectivity = kneighbors_graph(
          X, n_neighbors=10, include_self=False
      )
  
      # make connectivity symmetric
      connectivity = 0.5 * (connectivity + connectivity.T)
  
      # Generate the new colors:
      if algorithm == "MiniBatchKMeans":
          model = cluster.MiniBatchKMeans(
              n_clusters=n_clusters, n_init=3
          )
  
      elif algorithm == "Birch":
          model = cluster.Birch(n_clusters=n_clusters)
  
      elif algorithm == "DBSCAN":
          model = cluster.DBSCAN(eps=0.2)
  
      elif algorithm == "AffinityPropagation":
          model = cluster.AffinityPropagation(
              damping=0.9, preference=-200
          )
  
      elif algorithm == "MeanShift":
          model = cluster.MeanShift(
              bandwidth=bandwidth, bin_seeding=True
          )
  
      elif algorithm == "SpectralClustering":
          model = cluster.SpectralClustering(
              n_clusters=n_clusters,
              eigen_solver="arpack",
              affinity="nearest_neighbors",
          )
  
      elif algorithm == "Ward":
          model = cluster.AgglomerativeClustering(
              n_clusters=n_clusters,
              linkage="ward",
              connectivity=connectivity,
          )
  
      elif algorithm == "AgglomerativeClustering":
          model = cluster.AgglomerativeClustering(
              linkage="average",
              affinity="cityblock",
              n_clusters=n_clusters,
              connectivity=connectivity,
          )
  
      model.fit(X)
  
      if hasattr(model, "labels_"):
          y_pred = model.labels_.astype(int)
      else:
          y_pred = model.predict(X)
  
      return X, y_pred
  
file_path: bokeh/examples/server/app/clustering/main.py
imports: import numpy
  from sklearn import cluster, datasets
  from sklearn.neighbors import kneighbors_graph
  from sklearn.preprocessing import StandardScaler
  from bokeh.io import curdoc
  from bokeh.layouts import column, row
  from bokeh.models import ColumnDataSource, Select, Slider
  from bokeh.palettes import Spectral6
  from bokeh.plotting import figure
label_desc: Use image node_id 1 for calling a global function with example usage: clustering(X, algorithm, n_clusters) and returns: X,  y_pred