class_docstr: RandomStratified Splitter class.
  
  For sparse multitask datasets, a standard split offers no guarantees that the
  splits will have any activate compounds. This class guarantees that each task
  will have a proportional split of the activates in a split. TO do this, a
  ragged split is performed with different numbers of compounds taken from each
  task. Thus, the length of the split arrays may exceed the split of the
  original array. That said, no datapoint is copied to more than one split, so
  correctness is still ensured.
  
  Note that this splitter is only valid for boolean label data.
  
  TODO(rbharath): This splitter should be refactored to match style of other
  splitter classes.
class_docstr_tok: ["RandomStratified","Splitter","class",".","For","sparse","multitask","datasets",",","a","standard","split","offers","no","guarantees","that","the","splits","will","have","any","activate","compounds",".","This","class","guarantees","that","each","task","will","have","a","proportional","split","of","the","activates","in","a","split",".","TO","do","this",",","a","ragged","split","is","performed","with","different","numbers","of","compounds","taken","from","each","task",".","Thus",",","the","length","of","the","split","arrays","may","exceed","the","split","of","the","original","array",".","That","said",",","no","datapoint","is","copied","to","more","than","one","split",",","so","correctness","is","still","ensured",".","Note","that","this","splitter","is","only","valid","for","boolean","label","data",".","TODO","(","rbharath",")",":","This","splitter","should","be","refactored","to","match","style","of","other","splitter","classes","."]
docstr: Needs custom implementation due to ragged splits for stratification.
docstr_tok: ["Needs","custom","implementation","due","to","ragged","splits","for","stratification","."]
code: def k_fold_split(self, dataset, k, directories=None):
      """Needs custom implementation due to ragged splits for stratification."""
      log("Computing K-fold split", self.verbose)
      if directories is None:
          directories = [tempfile.mkdtemp() for _ in range(k)]
      else:
          assert len(directories) == k
      fold_datasets = []
      # rem_dataset is remaining portion of dataset
      rem_dataset = dataset
      for fold in range(k):
          # Note starts as 1/k since fold starts at 0. Ends at 1 since fold goes up
          # to k-1.
          frac_fold = 1.0 / (k - fold)
          fold_dir = directories[fold]
          rem_dir = tempfile.mkdtemp()
          fold_dataset, rem_dataset = self.split(
              rem_dataset, frac_fold, [fold_dir, rem_dir]
          )
          fold_datasets.append(fold_dataset)
      return fold_datasets
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import unicode_literals
  import tempfile
  import numpy
  import itertools
  from rdkit import Chem
  from rdkit import DataStructs
  from rdkit.Chem import AllChem
  from rdkit.ML.Cluster import Butina
  import deepchem
  from deepchem.data import DiskDataset
  from deepchem.utils import ScaffoldGenerator
  from deepchem.utils.save import log
  from deepchem.data import NumpyDataset
  from deepchem.utils.save import load_data
label_desc: Use image node_id 5 for calling the RandomStratifiedSplitter obj's underlying member method code with example usage: obj.k_fold_split(dataset, k, directories) and returns: fold_datasets