code: def run_clustering_experiment(
      trainX,
      clusterer,
      results_path,
      trainY=None,
      testX=None,
      testY=None,
      cls_name=None,
      dataset_name=None,
      resample_id=0,
      overwrite=True,
  ):
      """Run a clustering experiment and save the results to file.
  
      Method to run a basic experiment and write the results to files called
      testFold<resampleID>.csv and, if required, trainFold<resampleID>.csv. This
      version loads the data from file based on a path. The clusterer is always trained on
      the required input data trainX. Output to trainResample<resampleID>.csv will be
      the predicted clusters of trainX. If trainY is also passed, these are written to
      file. If the clusterer makes probabilistic predictions, these are also written to
      file. See write_results_to_uea_format for more on the output. Be warned,
      this method will always overwrite existing results, check bvefore calling or use
      load_and_run_clustering_experiment instead.
  
      Parameters
      ----------
      trainX : pd.DataFrame or np.array
          The data to cluster.
      clusterer : BaseClusterer
          The clustering object
      results_path : str
          Where to write the results to
      trainY : np.array, default = None
          Train data tue class labels, only used for file writing, ignored by the
          clusterer
      testX : pd.DataFrame or np.array, default = None
          Test attribute data, if present it is used for predicting testY
      testY : np.array, default = None
          Test data true class labels, only used for file writing, ignored by the
          clusterer
      cls_name : str, default = None
          Name of the clusterer, written to the results file, ignored if None
      dataset_name : str, default = None
          Name of problem, written to the results file, ignored if None
      resample_id : int, default = 0
          Resample identifier, defaults to 0
      """
      if not overwrite:
          full_path = (
              results_path
              + "/"
              + cls_name
              + "/Predictions/"
              + dataset_name
              + "/testResample"
              + str(resample_id)
              + ".csv"
          )
          if os.path.exists(full_path):
              return
  
      # Build the clusterer on train data, recording how long it takes
      le = preprocessing.LabelEncoder()
      le.fit(trainY)
      trainY = le.transform(trainY)
      testY = le.transform(testY)
      start = int(round(time.time() * 1000))
      clusterer.fit(trainX)
      build_time = int(round(time.time() * 1000)) - start
      start = int(round(time.time() * 1000))
      train_preds = clusterer.predict(trainX)
      build_time = int(round(time.time() * 1000)) - start
      train_probs = clusterer.predict_proba(trainX)
  
      start = int(round(time.time() * 1000))
      test_preds = clusterer.predict(testX)
      test_time = int(round(time.time() * 1000)) - start
      test_probs = clusterer.predict_proba(testX)
      second = str(clusterer.get_params())
      second.replace("\n", " ")
      second.replace("\r", " ")
      third = "0," + str(build_time) + "," + str(
          test_time
      ) + ",-1,-1," "" + str(len(np.unique(trainY))) + "," + str(
          len(np.unique(trainY))
      )
      write_results_to_uea_format(
          first_line_comment="Generated by clustering_experiments on "
          + str(datetime.today()),
          second_line=second,
          third_line=third,
          output_path=results_path,
          estimator_name=cls_name,
          resample_seed=resample_id,
          y_pred=test_preds,
          predicted_probs=test_probs,
          dataset_name=dataset_name,
          y_true=testY,
          split="TEST",
          full_path=False,
          timing_type="MILLISECONDS",
      )
  
      #        preds = form_cluster_list(clusters, len(testY))
      if "Composite" in cls_name:
          second = "Para info too long!"
      else:
          second = str(clusterer.get_params())
          second.replace("\n", " ")
          second.replace("\r", " ")
      third = "0," + str(build_time) + "," + str(
          test_time
      ) + ",-1,-1," "" + str(len(np.unique(trainY))) + "," + str(
          len(np.unique(trainY))
      )
      write_results_to_uea_format(
          first_line_comment="Generated by clustering_experiments on "
          + str(datetime.today()),
          second_line=second,
          third_line=third,
          output_path=results_path,
          estimator_name=cls_name,
          resample_seed=resample_id,
          y_pred=train_preds,
          predicted_probs=train_probs,
          dataset_name=dataset_name,
          y_true=trainY,
          split="TRAIN",
          full_path=False,
          timing_type="MILLISECONDS",
      )
  
file_path: sktime/sktime/benchmarking/experiments.py
imports: import os
  import time
  from datetime import datetime
  import numpy
  from sklearn import preprocessing
  from sklearn.metrics import accuracy_score
  from sklearn.model_selection import cross_val_predict
  from sktime.datasets import load_from_tsfile_to_dataframe
  from sktime.datasets import write_results_to_uea_format
  from sktime.utils.sampling import stratified_resample
label_desc: Use image node_id 1 for calling a global function with example usage: run_clustering_experiment(trainX, clusterer, results_path, trainY, testX, testY, cls_name, dataset_name, resample_id, overwrite) without return types