code: def get_m4_by_freq(
      context_length=72,
      prediction_length=24,
      len_per_ts=200,
      num_ts=50,
      num_groups=6,
      file_name="m4_freq",
  ):
      dataset_group = [[] for i in range(num_groups)]
      whole_data = []
      ret = dict()
      datasets_name = [
          "m4_hourly",
          "m4_daily",
          "m4_weekly",
          "m4_monthly",
          "m4_quarterly",
          "m4_yearly",
      ]
      hours_factor = [
          1,
          24,
          24 * 7,
          24 * 7 * 30,
          24 * 7 * 30 * 3,
          24 * 7 * 30 * 3 * 4,
      ]
      for i in range(num_groups):
          dataset = get_dataset(datasets_name[i])
          len_sample = context_length + prediction_length
          it = iter(dataset.train)
          for j in range(num_ts):
              train_entry = next(it)
              unsplit_ts = train_entry["target"]
              # unsplit_start = train_entry['start']
              unsplit_start = pd.Timestamp("1990-01-01")
              for ts_sample_start in range(
                  0, len_per_ts - len_sample, prediction_length
              ):
                  if len_sample > len(unsplit_ts):
                      continue
                  ts_slice = unsplit_ts[
                      ts_sample_start : ts_sample_start + len_sample
                  ]
                  if len(ts_slice) < len_sample:
                      continue
                  nu = 1 + sum(ts_slice) / len_sample
                  ts_slice = [i / nu for i in ts_slice]
                  whole_data.append(
                      {
                          "target": ts_slice,
                          "start": unsplit_start,
                          "feat_static_cat": train_entry[
                              "feat_static_cat"
                          ],
                      }
                  )
                  dataset_group[i].append(
                      {
                          "target": ts_slice,
                          "start": unsplit_start,
                          "feat_static_cat": train_entry[
                              "feat_static_cat"
                          ],
                      }
                  )
                  # unsplit_start += pd.Timedelta(hours=prediction_length*hours_factor[i])
                  unsplit_start += pd.Timedelta(hours=prediction_length)
      # for j in range(len(dataset_group)):
      #    print(len(dataset_group[i]))
      # import pdb;pdb.set_trace()
      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=dataset.metadata.freq
      )
      group_data_list = []
      for group in dataset_group:
          random.shuffle(group)
          group_data_list.append(
              ListDataset(group, freq=dataset.metadata.freq)
          )
      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
  
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
label_desc: Use image node_id 1 for calling a global function with example usage: get_m4_by_freq(context_length, prediction_length, len_per_ts, num_ts, num_groups, file_name) and returns: True