code: def infer_frequency(df, freq, n_lags, min_freq_percentage=0.7):
      """Automatically infers frequency of dataframe.
  
      Parameters
      ----------
          df : pd.DataFrame
              Dataframe with columns ``ds`` datestamps and ``y`` time series values, and optionally``ID``
          freq : str
              Data step sizes, i.e. frequency of data recording,
  
              Note
              ----
              Any valid frequency for pd.date_range, such as ``5min``, ``D``, ``MS`` or ``auto`` (default) to
              automatically set frequency.
          n_lags : int
              identical to NeuralProphet
          min_freq_percentage : float
              threshold for defining major frequency of data (default: ``0.7``
  
  
  
      Returns
      -------
          str
              Valid frequency tag according to major frequency.
  
      """
      df, _, _, _ = prep_or_copy_df(df)
      freq_df = list()
      for df_name, df_i in df.groupby("ID"):
          freq_df.append(
              _infer_frequency(df_i, freq, min_freq_percentage)
          )
      if len(set(freq_df)) != 1 and n_lags > 0:
          raise ValueError(
              "One or more dataframes present different major frequencies, please make sure all dataframes present the \
                  same major frequency for auto-regression"
          )
      elif len(set(freq_df)) != 1 and n_lags == 0:
          # The most common freq is set as the main one (but it does not really matter for Prophet approach)
          freq_str = max(set(freq_df), key=freq_df.count)
          log.warning(
              f"One or more major frequencies are different - setting main frequency as {freq_str}"
          )
      else:
          freq_str = freq_df[0]
      return freq_str
  
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 31 for calling a global function with example usage: infer_frequency(df, freq, n_lags, min_freq_percentage) and returns: freq_str