class_docstr: Class for doing data splits by stratification on a single task.
  
  Examples
  --------
  >>> n_samples = 100
  >>> n_features = 10
  >>> n_tasks = 10
  >>> X = np.random.rand(n_samples, n_features)
  >>> y = np.random.rand(n_samples, n_tasks)
  >>> w = np.ones_like(y)
  >>> dataset = DiskDataset.from_numpy(np.ones((100,n_tasks)), np.ones((100,n_tasks)))
  >>> splitter = SingletaskStratifiedSplitter(task_number=5)
  >>> train_dataset, test_dataset = splitter.train_test_split(dataset)
class_docstr_tok: ["Class","for","doing","data","splits","by","stratification","on","a","single","task",".","Examples","--","--","--","--",">",">",">","n_samples","=","100",">",">",">","n_features","=","10",">",">",">","n_tasks","=","10",">",">",">","X","=","np.random.rand","(","n_samples",",","n_features",")",">",">",">","y","=","np.random.rand","(","n_samples",",","n_tasks",")",">",">",">","w","=","np.ones_like","(","y",")",">",">",">","dataset","=","DiskDataset.from_numpy","(","np.ones","(","(","100",",","n_tasks",")",")",",","np.ones","(","(","100",",","n_tasks",")",")",")",">",">",">","splitter","=","SingletaskStratifiedSplitter","(","task_number=5",")",">",">",">","train_dataset",",","test_dataset","=","splitter.train_test_split","(","dataset",")"]
docstr: Splits compounds into k-folds using stratified sampling.
  Overriding base class k_fold_split.
  
  Parameters
  ----------
  dataset: Dataset
      Dataset to be split.
  k: int
      Number of folds to split `dataset` into.
  directories: List[str], optional (default None)
      List of length k filepaths to save the result disk-datasets.
  seed: int, optional (default None)
      Random seed to use.
  log_every_n: int, optional (default None)
      Log every n examples (not currently used).
  
  Returns
  -------
  fold_datasets: List[Dataset]
      List of dc.data.Dataset objects
docstr_tok: ["Splits","compounds","into","k-folds","using","stratified","sampling",".","Overriding","base","class","k_fold_split",".","Parameters","--","--","--","--","--","dataset",":","Dataset","Dataset","to","be","split",".","k",":","int","Number","of","folds","to","split","`","dataset","`","into",".","directories",":","List","[","str","]",",","optional","(","default","None",")","List","of","length","k","filepaths","to","save","the","result","disk-datasets",".","seed",":","int",",","optional","(","default","None",")","Random","seed","to","use",".","log_every_n",":","int",",","optional","(","default","None",")","Log","every","n","examples","(","not","currently","used",")",".","Returns","--","--","--","-","fold_datasets",":","List","[","Dataset","]","List","of","dc.data.Dataset","objects"]
code: def k_fold_split(  # type: ignore [override]
      self,
      dataset: Dataset,
      k: int,
      directories: Optional[List[str]] = None,
      seed: Optional[int] = None,
      log_every_n: Optional[int] = None,
      **kwargs,
  ) -> List[Dataset]:
      """
      Splits compounds into k-folds using stratified sampling.
      Overriding base class k_fold_split.
  
      Parameters
      ----------
      dataset: Dataset
          Dataset to be split.
      k: int
          Number of folds to split `dataset` into.
      directories: List[str], optional (default None)
          List of length k filepaths to save the result disk-datasets.
      seed: int, optional (default None)
          Random seed to use.
      log_every_n: int, optional (default None)
          Log every n examples (not currently used).
  
      Returns
      -------
      fold_datasets: List[Dataset]
          List of dc.data.Dataset objects
      """
      logger.info("Computing K-fold split")
      if directories is None:
          directories = [tempfile.mkdtemp() for _ in range(k)]
      else:
          assert len(directories) == k
  
      y_s = dataset.y[:, self.task_number]
      sortidx = np.argsort(y_s)
      sortidx_list = np.array_split(sortidx, k)
  
      fold_datasets = []
      for fold in range(k):
          fold_dir = directories[fold]
          fold_ind = sortidx_list[fold]
          fold_dataset = dataset.select(fold_ind, fold_dir)
          fold_datasets.append(fold_dataset)
      return fold_datasets
  
imports: import inspect
  import itertools
  import logging
  import os
  import random
  import tempfile
  from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, Union
  import deepchem
  import numpy
  import pandas
  from deepchem.data import Dataset, DiskDataset
  from deepchem.utils import get_print_threshold
label_desc: Use image node_id 2 for calling the SingletaskStratifiedSplitter obj's underlying member method code with example usage: obj.k_fold_split(dataset, k, directories, seed, log_every_n) and returns: fold_datasets