code: def crossvalidation_split_df(
      df,
      n_lags,
      n_forecasts,
      k,
      fold_pct,
      fold_overlap_pct=0.0,
      global_model_cv_type="global-time",
  ):
      """Splits data in k folds for crossvalidation.
  
      Parameters
      ----------
          df : pd.DataFrame
              data
          n_lags : int
              identical to NeuralProphet
          n_forecasts : int
              identical to NeuralProphet
          k : int
              number of CV folds
          fold_pct : float
              percentage of overall samples to be in each fold
          fold_overlap_pct : float
              percentage of overlap between the validation folds (default: 0.0)
          global_model_cv_type : str
              Type of crossvalidation to apply to the time series.
  
                  options:
  
                      ``global-time`` (default) crossvalidation is performed according to a time stamp threshold.
  
                      ``local`` each episode will be crossvalidated locally (may cause time leakage among different
                      episodes)
  
                      ``intersect`` only the time intersection of all the episodes will be considered. A considerable
                      amount of data may not be used. However, this approach guarantees an equal number of train/test
                      samples for each episode.
  
      Returns
      -------
          list of k tuples [(df_train, df_val), ...]
  
              training data
  
              validation data
      """
      df, _, _, _ = prep_or_copy_df(df)
      folds = []
      if len(df["ID"].unique()) == 1:
          for df_name, df_i in df.groupby("ID"):
              folds = _crossvalidation_split_df(
                  df_i,
                  n_lags,
                  n_forecasts,
                  k,
                  fold_pct,
                  fold_overlap_pct,
              )
      else:
          if (
              global_model_cv_type == "global-time"
              or global_model_cv_type is None
          ):
              # Use time threshold to perform crossvalidation
              # (the distribution of data of different episodes may not be equivalent)
              folds = _crossvalidation_with_time_threshold(
                  df, n_lags, n_forecasts, k, fold_pct, fold_overlap_pct
              )
          elif global_model_cv_type == "local":
              # Crossvalidate time series locally (time leakage may be a problem)
              folds_dict = {}
              for df_name, df_i in df.groupby("ID"):
                  folds_dict[df_name] = _crossvalidation_split_df(
                      df_i,
                      n_lags,
                      n_forecasts,
                      k,
                      fold_pct,
                      fold_overlap_pct,
                  )
              folds = unfold_dict_of_folds(folds_dict, k)
          elif global_model_cv_type == "intersect":
              # Use data only from the time period of intersection among time series
              folds_dict = {}
              # Check for intersection of time so time leakage does not occur among different time series
              start_date, end_date = find_valid_time_interval_for_cv(df)
              for df_name, df_i in df.groupby("ID"):
                  mask = (df_i["ds"] >= start_date) & (
                      df_i["ds"] <= end_date
                  )
                  df_i = df_i[mask].copy(deep=True)
                  folds_dict[df_name] = _crossvalidation_split_df(
                      df_i,
                      n_lags,
                      n_forecasts,
                      k,
                      fold_pct,
                      fold_overlap_pct,
                  )
              folds = unfold_dict_of_folds(folds_dict, k)
          else:
              raise ValueError(
                  "Please choose a valid type of global model crossvalidation (i.e. global-time, local, or intersect)"
              )
      return folds
  
imports: from __future__ import annotations
  import logging
  import math
  from collections import OrderedDict
  from dataclasses import dataclass
  from typing import TYPE_CHECKING, List, Optional, Tuple
  import numpy
  import pandas
label_desc: Use image node_id 15 for calling a global function with example usage: crossvalidation_split_df(df, n_lags, n_forecasts, k, fold_pct, fold_overlap_pct, global_model_cv_type) and returns: folds