code: def elbow_curve_from_results(
      n_clusters, sum_of_squares, times, ax=None
  ):
      """
      Same as `elbow_curve`, but it takes the number of clusters and sum of
      squares as inputs. Useful if you want to train the models yourself.
      """
      # TODO: unit test this
      # TODO: also test with unsorted input
      idx = np.argsort(n_clusters)
      n_clusters = np.array(n_clusters)[idx]
      sum_of_squares = np.array(sum_of_squares)[idx]
  
      if ax is None:
          ax = plt.gca()
  
      ax.set_title("Elbow Plot")
      ax.plot(n_clusters, sum_of_squares, "b*-", label="Elbow")
      ax.grid(True)
      ax.set_xlabel("Number of clusters")
      ax.set_ylabel("Sum of Squared Errors")
  
      handles, labels = ax.get_legend_handles_labels()
      if times is not None:
          times = np.array(times)[idx]
          ax2_color = "green"
          ax2 = ax.twinx()
          ax2.plot(
              n_clusters,
              times,
              ":",
              alpha=0.75,
              color=ax2_color,
              label="Fitting time",
          )
          ax2.set_ylabel(
              "Clustering duration (seconds)",
              color=ax2_color,
              alpha=0.75,
          )
          ax2.tick_params(colors=ax2_color)
  
          handles2, labels2 = ax2.get_legend_handles_labels()
          handles = handles + handles2
          labels = labels + labels2
  
      ax.legend(handles, labels)
      return ax
  
file_path: sklearn-evaluation/src/sklearn_evaluation/plot/clustering.py
imports: import time
  import matplotlib.pyplot
  import numpy
  from sklearn.base import clone
  from sklearn.metrics import silhouette_samples, silhouette_score
  from sklearn.preprocessing import LabelEncoder
  from joblib import Parallel, delayed
  from sklearn_evaluation.telemetry import SKLearnEvaluationLogger
  from ploomber_core.exceptions import modify_exceptions
  from ploomber_core import deprecated
label_desc: Use image node_id 2 for calling a global function with example usage: elbow_curve_from_results(n_clusters, sum_of_squares, times, ax) and returns: ax