class_docstr: Provides a simple interface for splitting datasets task-wise.
  
  For some learning problems, the training and test datasets should
  have different tasks entirely. This is a different paradigm from the
  usual Splitter, which ensures that split datasets have different
  datapoints, not different tasks.
docstr: Performs a K-fold split of the tasks for dataset.
  
  If split is uneven, spillover goes to last fold.
  
  Parameters
  ----------
  dataset: dc.data.Dataset
      Dataset to be split
  K: int
      Number of splits to be made
docstr_tok: ["Performs","a","K-fold","split","of","the","tasks","for","dataset",".","If","split","is","uneven",",","spillover","goes","to","last","fold",".","Parameters","--","--","--","--","--","dataset",":","dc.data.Dataset","Dataset","to","be","split","K",":","int","Number","of","splits","to","be","made"]
code: def k_fold_split(self, dataset, K):
      """Performs a K-fold split of the tasks for dataset.
  
      If split is uneven, spillover goes to last fold.
  
      Parameters
      ----------
      dataset: dc.data.Dataset
          Dataset to be split
      K: int
          Number of splits to be made
      """
      n_tasks = len(dataset.get_task_names())
      n_per_fold = int(np.round(n_tasks / float(K)))
      if K * n_per_fold != n_tasks:
          print(
              "Assigning extra tasks to last fold due to uneven split"
          )
  
      X, y, w, ids = dataset.X, dataset.y, dataset.w, dataset.ids
  
      fold_datasets = []
      for fold in range(K):
          if fold != K - 1:
              fold_tasks = range(
                  fold * n_per_fold, (fold + 1) * n_per_fold
              )
          else:
              fold_tasks = range(fold * n_per_fold, n_tasks)
          if len(w.shape) == 1:
              w_tasks = w
          elif w.shape[1] == 1:
              w_tasks = w[:, 0]
          else:
              w_tasks = w[:, fold_tasks]
          fold_datasets.append(
              NumpyDataset(X, y[:, fold_tasks], w_tasks, ids)
          )
      return fold_datasets
  
file_path: deepchem/deepchem/splits/task_splitter.py
imports: import numpy
  from deepchem.data import NumpyDataset
  from deepchem.splits import Splitter
label_desc: Use image node_id 3 for calling the TaskSplitter obj's underlying member method code with example usage: obj.k_fold_split(dataset, K) and returns: fold_datasets