code: def run_classification_experiment(
      X_train,
      y_train,
      X_test,
      y_test,
      classifier,
      results_path,
      cls_name="",
      dataset="",
      resample_id=0,
      train_file=False,
      test_file=True,
  ):
      """Run a classification 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.
  
      Parameters
      ----------
      X_train : pd.DataFrame or np.array
          The data to train the classifier.
      y_train : np.array, default = None
          Training data class labels.
      X_test : pd.DataFrame or np.array, default = None
          The data used to test the trained classifier.
      y_test : np.array, default = None
          Testing data class labels.
      classifier : BaseClassifier
          Classifier to be used in the experiment.
      results_path : str
          Location of where to write results. Any required directories will be created.
      cls_name : str, default=""
          Name of the classifier.
      dataset : str, default=""
          Name of problem.
      resample_id : int, default=0
          Seed for resampling. If set to 0, the default train/test split from file is
          used. Also used in output file name.
      train_file : bool, default=False
          Whether to generate train files or not. If true, it performs a 10-fold
          cross-validation on the train data and saves. If the classifier can produce its
          own estimates, those are used instead.
      test_file : bool, default=True:
           Whether to generate test files or not. If the classifier can generate its own
           train probabilities, the classifier will be built but no file will be output.
      """
      if not test_file and not train_file:
          raise Exception(
              "Both test_file and train_file are set to False. "
              "At least one must be output."
          )
  
      le = preprocessing.LabelEncoder()
      y_train = le.fit_transform(y_train)
      y_test = le.transform(y_test)
  
      encoder_dict = {label: i for i, label in enumerate(le.classes_)}
      classifier_train_probs = train_file and callable(
          getattr(classifier, "_get_train_probs", None)
      )
      build_time = -1
  
      if test_file or classifier_train_probs:
          start = int(round(time.time() * 1000))
          classifier.fit(X_train, y_train)
          build_time = int(round(time.time() * 1000)) - start
  
      if test_file:
          start = int(round(time.time() * 1000))
          probs = classifier.predict_proba(X_test)
          test_time = int(round(time.time() * 1000)) - start
  
          if "composite" in cls_name.lower():
              second = "Para info too long!"
          else:
              second = str(classifier.get_params())
          second.replace("\n", " ")
          second.replace("\r", " ")
  
          # Line 3 format:
          preds = classifier.classes_[np.argmax(probs, axis=1)]
          acc = accuracy_score(y_test, preds)
          third = (
              str(acc)  # 1. accuracy
              + ","
              + str(build_time)  # 2. fit time
              + ","
              + str(test_time)  # 3. predict time
              + ",-1,-1,"  # 4. 5. benchmark time, memory (to do)
              + str(len(classifier.classes_))  # 6. number of classes
              + ",,-1,-1"  # 7. 8. 9.
          )
  
          write_results_to_uea_format(
              second_line=second,
              third_line=third,
              first_line_comment="PREDICTIONS,Generated by experiments.py on "
              + datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
              + ". Encoder dictionary: "
              + str(encoder_dict),
              timing_type="MILLISECONDS",
              output_path=results_path,
              estimator_name=cls_name,
              resample_seed=resample_id,
              y_pred=preds,
              predicted_probs=probs,
              dataset_name=dataset,
              y_true=y_test,
              split="TEST",
              full_path=False,
          )
  
      if train_file:
          start = int(round(time.time() * 1000))
          if (
              classifier_train_probs
          ):  # Normally can only do this if test has been built
              train_probs = classifier._get_train_probs(
                  X_train, y_train
              )
          else:
              cv_size = 10
              _, counts = np.unique(y_train, return_counts=True)
              min_class = np.min(counts)
              if min_class < cv_size:
                  cv_size = min_class
  
              train_probs = cross_val_predict(
                  classifier,
                  X_train,
                  y=y_train,
                  cv=cv_size,
                  method="predict_proba",
              )
          train_time = int(round(time.time() * 1000)) - start
  
          if "composite" in cls_name.lower():
              second = "Para info too long!"
          else:
              second = str(classifier.get_params())
          second.replace("\n", " ")
          second.replace("\r", " ")
  
          train_preds = classifier.classes_[
              np.argmax(train_probs, axis=1)
          ]
          train_acc = accuracy_score(y_train, train_preds)
          third = (
              str(train_acc)
              + ","
              + str(build_time)
              + ",-1,-1,-1,"
              + str(len(classifier.classes_))
              + ",,"
              + str(train_time)
              + ","
              + str(build_time + train_time)
          )
  
          write_results_to_uea_format(
              second_line=second,
              third_line=third,
              first_line_comment="PREDICTIONS,Generated by classification_experiments.py "
              "on "
              + datetime.now().strftime("%d/%m/%Y, %H:%M:%S")
              + ". Encoder dictionary: "
              + str(encoder_dict),
              timing_type="MILLISECONDS",
              output_path=results_path,
              estimator_name=cls_name,
              resample_seed=resample_id,
              y_pred=train_preds,
              predicted_probs=train_probs,
              dataset_name=dataset,
              y_true=y_train,
              split="TRAIN",
              full_path=False,
          )
  
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 3 for calling a global function with example usage: run_classification_experiment(X_train, y_train, X_test, y_test, classifier, results_path, cls_name, dataset, resample_id, train_file, test_file) without return types