code: def cross_validated(
      x,
      num_folds=10,
      y=None,
      strata=None,
      folds=None,
      num_iter=1,
      regenerate_folds=False,
      clusters=None,
      aggregator=mean,
  ):
      """Function decorator to perform cross-validation as configured.
  
      :param x: data to be used for cross-validation
      :param num_folds: number of cross-validation folds (default 10)
      :param y: (optional) labels to be used for cross-validation.
          If specified, len(labels) must equal len(x)
      :param strata: (optional) strata to account for when generating folds.
          Strata signify instances that must be spread across folds.
          Not every instance must be in a stratum.
          Specify strata as a list of lists of instance indices.
      :param folds: (optional) prespecified cross-validation folds to be used (list of lists (iterations) of lists (folds)).
      :param num_iter: (optional) number of iterations to use (default 1)
      :param regenerate_folds: (optional) whether or not to regenerate folds on every evaluation (default false)
      :param clusters: (optional) clusters to account for when generating folds.
          Clusters signify instances that must be assigned to the same fold.
          Not every instance must be in a cluster.
          Specify clusters as a list of lists of instance indices.
      :param aggregator: function to aggregate scores of different folds (default: mean)
      :returns: a :class:`cross_validated_callable` with the proper configuration.
  
      This resulting decorator must be used on a function with the following signature (+ potential other arguments):
  
      :param x_train: training data
      :type x_train: iterable
      :param y_train: training labels (optional)
      :type y_train: iterable
      :param x_test: testing data
      :type x_test: iterable
      :param y_test: testing labels (optional)
      :type y_test: iterable
  
      `y_train` and `y_test` must be available of the `y` argument to this function is not None.
  
      These 4 keyword arguments will be bound upon decoration.
      Further arguments will remain free (e.g. hyperparameter names).
  
      >>> data = list(range(5))
      >>> @cross_validated(x=data, num_folds=5, folds=[[[i] for i in range(5)]], aggregator=identity)
      ... def f(x_train, x_test, a):
      ...     return x_test[0] + a
      >>> f(a=1)
      [1, 2, 3, 4, 5]
      >>> f(1)
      [1, 2, 3, 4, 5]
      >>> f(a=2)
      [2, 3, 4, 5, 6]
  
      The number of folds must be less than or equal to the size of the data.
  
      >>> data = list(range(5))
      >>> @cross_validated(x=data, num_folds=6) #doctest:+SKIP
      ... def f(x_train, x_test, a):
      ...     return x_test[0] + a
      AssertionError
  
      The number of labels (if specified) must match the number of data instances.
  
      >>> data = list(range(5))
      >>> labels = list(range(3))
      >>> @cross_validated(x=data, y=labels, num_folds=2) #doctest:+SKIP
      ... def f(x_train, x_test, a):
      ...     return x_test[0] + a
      AssertionError
  
      """
      assert num_folds <= len(x)
      assert y is None or len(y) == len(x)
      args = dict(locals())
  
      def wrapper(f):
          args["f"] = f
          return cross_validated_callable(**args)
  
      return wrapper
  
imports: import math
  import random
  import itertools
  import functools
  import operator
  import array
  import inspect
label_desc: Use image node_id 10 for calling a global function with example usage: cross_validated(x, num_folds, y, strata, folds, num_iter, regenerate_folds, clusters, aggregator) and returns: wrapper, cross_validated_callable