code: def KMeans_m5_dataset(
      num_ts_=1,
      num_groups=16,
      context_length=72,
      prediction_length=24,
      file_name="default",
  ):
      df = pd.read_csv("sales_train_evaluation.csv")
      dataset_group = [[] for i in range(num_groups)]
      whole_data = []
      ret = dict()
      # num_ts = int(dataset.metadata.feat_static_cat[0].cardinality)
      num_ts = num_ts_
      len_sample = context_length + prediction_length
      # compute mean and variance
      df = df.iloc[:num_ts, :]
      df["mean"] = df.iloc[:, 1947 - len_sample : 1947].mean(axis=1)
      df["var"] = df.iloc[:, 1947 - len_sample : 1947].var(axis=1)
      df["mean"] = (df["mean"] - df["mean"].min()) / (
          df["mean"].max() - df["mean"].min()
      )
      df["var"] = (df["var"] - df["var"].min()) / (
          df["var"].max() - df["var"].min()
      )
      df_feature = df.iloc[:, 2:6]
      df_feature = pd.get_dummies(df_feature, dummy_na=True)
      df_feature = pd.concat([df_feature, df.iloc[:, -2]], axis=1)
      feature = torch.from_numpy(df_feature.to_numpy()).contiguous()
      cl, c = KMeans(feature, num_groups)
      # print(cl)
      # import pdb;pdb.set_trace()
      sample_id = 0
      for i in range(num_ts):
          ts_slice = df.iloc[i : i + 1, 1947 - len_sample : 1947]
          ts_slice = torch.from_numpy(ts_slice.to_numpy())[0]
          # print(ts_slice)
          # import pdb;pdb.set_trace()
          gid = cl[sample_id]
          unsplit_start = pd.Timestamp("1990-01-01")
          dataset_group[gid].append(
              {
                  "target": ts_slice,
                  "start": unsplit_start,
              }  # , 'feat_static_cat': train_entry['feat_static_cat']}
          )
          whole_data.append(
              {
                  "target": ts_slice,
                  "start": unsplit_start,
              }  # , 'feat_static_cat': train_entry['feat_static_cat']}
          )
          sample_id += 1
      print(len(whole_data))
      ret["group_ratio"] = [
          len(i) / len(whole_data) for i in dataset_group
      ]
      print(ret["group_ratio"])
      random.shuffle(whole_data)
      ret["whole_data"] = ListDataset(whole_data, freq="1H")
      group_data_list = []
      for group in dataset_group:
          random.shuffle(group)
          group_data_list.append(ListDataset(group, freq="1H"))
      ret["group_data"] = group_data_list
      print("write whole data")
      with open(
          "synthetic_" + file_name + "_whole_data.csv", "wb"
      ) as output:
          pickle.dump(ret["whole_data"], output)
      print("write group data")
      with open(
          "synthetic_" + file_name + "_group_data.csv", "wb"
      ) as output:
          pickle.dump(ret, output)
      return True
  
file_path: gluonts/src/gluonts/nursery/SCott/dataset_tools/algo_clustering.py
imports: from pts.dataset.repository.datasets import get_dataset, dataset_recipes
  from pts.dataset.utils import to_pandas
  import numpy
  import pandas
  from pts.dataset import ListDataset
  import torch
  from pts.model.simple_feedforward import SimpleFeedForwardEstimator
  import pickle
  import json
  import random
  import time
  from matplotlib import pyplot
  from pykeops.torch import LazyTensor
label_desc: Use image node_id 4 for calling a global function with example usage: KMeans_m5_dataset(num_ts_, num_groups, context_length, prediction_length, file_name) and returns: True