class_docstr: RandomStratified Splitter class.
  
  For sparse multitask datasets, a standard split offers no guarantees
  that the splits will have any active compounds. This class tries to
  arrange that each split has a proportional number of the actives for each
  task. This is strictly guaranteed only for single-task datasets, but for
  sparse multitask datasets it usually manages to produces a fairly accurate
  division of the actives for each task.
  
  Note
  ----
  This splitter is primarily designed for boolean labeled data. It considers
  only whether a label is zero or non-zero. When labels can take on multiple
  non-zero values, it does not try to give each split a proportional fraction
  of the samples with each value.
  
  Examples
  --------
  >>> import deepchem as dc
  >>> import numpy as np
  >>> from typing import Sequence
  >>> # creation of demo data set with some smiles strings
  >>> smiles= ['C', 'CC', 'CCC', 'CCCC', 'CCCCC']
  >>> Xs = np.zeros(len(smiles))
  >>> # creation of a deepchem dataset with the smile codes in the ids field
  >>> dataset = dc.data.DiskDataset.from_numpy(X=Xs,ids=smiles)
  >>> randomstratifiedsplitter = dc.splits.RandomStratifiedSplitter()
  >>> train_dataset, test_dataset = randomstratifiedsplitter.train_test_split(dataset)
class_docstr_tok: ["RandomStratified","Splitter","class",".","For","sparse","multitask","datasets",",","a","standard","split","offers","no","guarantees","that","the","splits","will","have","any","active","compounds",".","This","class","tries","to","arrange","that","each","split","has","a","proportional","number","of","the","actives","for","each","task",".","This","is","strictly","guaranteed","only","for","single-task","datasets",",","but","for","sparse","multitask","datasets","it","usually","manages","to","produces","a","fairly","accurate","division","of","the","actives","for","each","task",".","Note","--","--","This","splitter","is","primarily","designed","for","boolean","labeled","data",".","It","considers","only","whether","a","label","is","zero","or","non-zero",".","When","labels","can","take","on","multiple","non-zero","values",",","it","does","not","try","to","give","each","split","a","proportional","fraction","of","the","samples","with","each","value",".","Examples","--","--","--","--",">",">",">","import","deepchem","as","dc",">",">",">","import","numpy","as","np",">",">",">","from","typing","import","Sequence",">",">",">","#","creation","of","demo","data","set","with","some","smiles","strings",">",">",">","smiles=","[","'","C","'",",","'CC","'",",","'CCC","'",",","'CCCC","'",",","'CCCCC","'","]",">",">",">","Xs","=","np.zeros","(","len","(","smiles",")",")",">",">",">","#","creation","of","a","deepchem","dataset","with","the","smile","codes","in","the","ids","field",">",">",">","dataset","=","dc.data.DiskDataset.from_numpy","(","X=Xs",",","ids=smiles",")",">",">",">","randomstratifiedsplitter","=","dc.splits.RandomStratifiedSplitter","(",")",">",">",">","train_dataset",",","test_dataset","=","randomstratifiedsplitter.train_test_split","(","dataset",")"]
docstr: Return indices for specified split
  
  Parameters
  ----------
  dataset: dc.data.Dataset
      Dataset to be split.
  seed: int, optional (default None)
      Random seed to use.
  frac_train: float, optional (default 0.8)
      The fraction of data to be used for the training split.
  frac_valid: float, optional (default 0.1)
      The fraction of data to be used for the validation split.
  frac_test: float, optional (default 0.1)
      The fraction of data to be used for the test split.
  log_every_n: int, optional (default None)
      Controls the logger by dictating how often logger outputs
      will be produced.
  
  Returns
  -------
  Tuple
      A tuple `(train_inds, valid_inds, test_inds)` of the indices (integers) for
      the various splits.
docstr_tok: ["Return","indices","for","specified","split","Parameters","--","--","--","--","--","dataset",":","dc.data.Dataset","Dataset","to","be","split",".","seed",":","int",",","optional","(","default","None",")","Random","seed","to","use",".","frac_train",":","float",",","optional","(","default","0.8",")","The","fraction","of","data","to","be","used","for","the","training","split",".","frac_valid",":","float",",","optional","(","default","0.1",")","The","fraction","of","data","to","be","used","for","the","validation","split",".","frac_test",":","float",",","optional","(","default","0.1",")","The","fraction","of","data","to","be","used","for","the","test","split",".","log_every_n",":","int",",","optional","(","default","None",")","Controls","the","logger","by","dictating","how","often","logger","outputs","will","be","produced",".","Returns","--","--","--","-","Tuple","A","tuple","`","(","train_inds",",","valid_inds",",","test_inds",")","`","of","the","indices","(","integers",")","for","the","various","splits","."]
code: def split(
      self,
      dataset: Dataset,
      frac_train: float = 0.8,
      frac_valid: float = 0.1,
      frac_test: float = 0.1,
      seed: Optional[int] = None,
      log_every_n: Optional[int] = None,
  ) -> Tuple:
      """Return indices for specified split
  
      Parameters
      ----------
      dataset: dc.data.Dataset
          Dataset to be split.
      seed: int, optional (default None)
          Random seed to use.
      frac_train: float, optional (default 0.8)
          The fraction of data to be used for the training split.
      frac_valid: float, optional (default 0.1)
          The fraction of data to be used for the validation split.
      frac_test: float, optional (default 0.1)
          The fraction of data to be used for the test split.
      log_every_n: int, optional (default None)
          Controls the logger by dictating how often logger outputs
          will be produced.
  
      Returns
      -------
      Tuple
          A tuple `(train_inds, valid_inds, test_inds)` of the indices (integers) for
          the various splits.
      """
      y_present = (dataset.y != 0) * (dataset.w != 0)
      if len(y_present.shape) == 1:
          y_present = np.expand_dims(y_present, 1)
      elif len(y_present.shape) > 2:
          raise ValueError(
              "RandomStratifiedSplitter cannot be applied when y has more than two dimensions"
          )
      if seed is not None:
          np.random.seed(seed)
  
      # Figure out how many positive samples we want for each task in each dataset.
  
      n_tasks = y_present.shape[1]
      indices_for_task = [
          np.random.permutation(np.nonzero(y_present[:, i])[0])
          for i in range(n_tasks)
      ]
      count_for_task = np.array([len(x) for x in indices_for_task])
      train_target = np.round(frac_train * count_for_task).astype(int)
      valid_target = np.round(frac_valid * count_for_task).astype(int)
      test_target = np.round(frac_test * count_for_task).astype(int)
  
      # Assign the positive samples to datasets.  Since a sample may be positive
      # on more than one task, we need to keep track of the effect of each added
      # sample on each task.  To try to keep everything balanced, we cycle through
      # tasks, assigning one positive sample for each one.
  
      train_counts = np.zeros(n_tasks, int)
      valid_counts = np.zeros(n_tasks, int)
      test_counts = np.zeros(n_tasks, int)
      set_target = [train_target, valid_target, test_target]
      set_counts = [train_counts, valid_counts, test_counts]
      set_inds: List[List[int]] = [[], [], []]
      assigned = set()
      max_count = np.max(count_for_task)
      for i in range(max_count):
          for task in range(n_tasks):
              indices = indices_for_task[task]
              if i < len(indices) and indices[i] not in assigned:
                  # We have a sample that hasn't been assigned yet.  Assign it to
                  # whichever set currently has the lowest fraction of its target for
                  # this task.
  
                  index = indices[i]
                  set_frac = [
                      1
                      if set_target[i][task] == 0
                      else set_counts[i][task] / set_target[i][task]
                      for i in range(3)
                  ]
                  set_index = np.argmin(set_frac)
                  set_inds[set_index].append(index)
                  assigned.add(index)
                  set_counts[set_index] += y_present[index]
  
      # The remaining samples are negative for all tasks.  Add them to fill out
      # each set to the correct total number.
  
      n_samples = y_present.shape[0]
      set_size = [
          int(np.round(n_samples * f))
          for f in (frac_train, frac_valid, frac_test)
      ]
      s = 0
      for i in np.random.permutation(range(n_samples)):
          if i not in assigned:
              while s < 2 and len(set_inds[s]) >= set_size[s]:
                  s += 1
              set_inds[s].append(i)
      return tuple(sorted(x) for x in set_inds)
  
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 1 for calling the RandomStratifiedSplitter obj's underlying member method code with example usage: obj.split(dataset, frac_train, frac_valid, frac_test, seed, log_every_n) and returns: tuple