class_docstr: Random split based on groupings.
  
  A splitter class that splits on groupings. An example use case is when
  there are multiple conformations of the same molecule that share the same
  topology.  This splitter subsequently guarantees that resulting splits
  preserve groupings.
  
  Note that it doesn't do any dynamic programming or something fancy to try
  to maximize the choice such that frac_train, frac_valid, or frac_test is
  maximized.  It simply permutes the groups themselves. As such, use with
  caution if the number of elements per group varies significantly.
  
  Examples
  --------
  >>> import deepchem as dc
  >>> import numpy as np
  >>> X=np.arange(12)
  >>> groups = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
  >>> splitter = dc.splits.RandomGroupSplitter(groups=groups)
  >>> dataset = dc.data.NumpyDataset(X)   # 12 elements
  >>> train, test = splitter.train_test_split(dataset, frac_train=0.75, seed=0)
  >>> print (train.ids) #array([6, 7, 8, 9, 10, 11, 3, 4, 5], dtype=object)
  [6 7 8 9 10 11 3 4 5]
class_docstr_tok: ["Random","split","based","on","groupings",".","A","splitter","class","that","splits","on","groupings",".","An","example","use","case","is","when","there","are","multiple","conformations","of","the","same","molecule","that","share","the","same","topology",".","This","splitter","subsequently","guarantees","that","resulting","splits","preserve","groupings",".","Note","that","it","does","n't","do","any","dynamic","programming","or","something","fancy","to","try","to","maximize","the","choice","such","that","frac_train",",","frac_valid",",","or","frac_test","is","maximized",".","It","simply","permutes","the","groups","themselves",".","As","such",",","use","with","caution","if","the","number","of","elements","per","group","varies","significantly",".","Examples","--","--","--","--",">",">",">","import","deepchem","as","dc",">",">",">","import","numpy","as","np",">",">",">","X=np.arange","(","12",")",">",">",">","groups","=","[","0",",","0",",","0",",","1",",","1",",","1",",","2",",","2",",","2",",","3",",","3",",","3","]",">",">",">","splitter","=","dc.splits.RandomGroupSplitter","(","groups=groups",")",">",">",">","dataset","=","dc.data.NumpyDataset","(","X",")","#","12","elements",">",">",">","train",",","test","=","splitter.train_test_split","(","dataset",",","frac_train=0.75",",","seed=0",")",">",">",">","print","(","train.ids",")","#","array","(","[","6",",","7",",","8",",","9",",","10",",","11",",","3",",","4",",","5","]",",","dtype=object",")","[","6","7","8","9","10","11","3","4","5","]"]
docstr: Return indices for specified split
  
  Parameters
  ----------
  dataset: Dataset
      Dataset to be split.
  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.
  seed: int, optional (default None)
      Random seed to use.
  log_every_n: int, optional (default None)
      Log every n examples (not currently used).
  
  Returns
  -------
  Tuple[List[int], List[int], List[int]]
      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",":","Dataset","Dataset","to","be","split",".","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",".","seed",":","int",",","optional","(","default","None",")","Random","seed","to","use",".","log_every_n",":","int",",","optional","(","default","None",")","Log","every","n","examples","(","not","currently","used",")",".","Returns","--","--","--","-","Tuple","[","List","[","int","]",",","List","[","int","]",",","List","[","int","]","]","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[List[int], List[int], List[int]]:
      """Return indices for specified split
  
      Parameters
      ----------
      dataset: Dataset
          Dataset to be split.
      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.
      seed: int, optional (default None)
          Random seed to use.
      log_every_n: int, optional (default None)
          Log every n examples (not currently used).
  
      Returns
      -------
      Tuple[List[int], List[int], List[int]]
          A tuple `(train_inds, valid_inds, test_inds` of the indices (integers) for
          the various splits.
      """
  
      assert len(self.groups) == dataset.X.shape[0]
      np.testing.assert_almost_equal(
          frac_train + frac_valid + frac_test, 1.0
      )
  
      if seed is not None:
          np.random.seed(seed)
  
      # dict is needed in case groups aren't strictly flattened or
      # hashed by something non-integer like
      group_dict: Dict[Any, List[int]] = {}
      for idx, g in enumerate(self.groups):
          if g not in group_dict:
              group_dict[g] = []
          group_dict[g].append(idx)
  
      group_idxs = np.array([g for g in group_dict.values()])
  
      num_groups = len(group_idxs)
      train_cutoff = int(frac_train * num_groups)
      valid_cutoff = int((frac_train + frac_valid) * num_groups)
      shuffled_group_idxs = np.random.permutation(range(num_groups))
  
      train_groups = shuffled_group_idxs[:train_cutoff]
      valid_groups = shuffled_group_idxs[train_cutoff:valid_cutoff]
      test_groups = shuffled_group_idxs[valid_cutoff:]
  
      train_idxs = list(itertools.chain(*group_idxs[train_groups]))
      valid_idxs = list(itertools.chain(*group_idxs[valid_groups]))
      test_idxs = list(itertools.chain(*group_idxs[test_groups]))
  
      return train_idxs, valid_idxs, test_idxs
  
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 RandomGroupSplitter obj's underlying member method code with example usage: obj.split(dataset, frac_train, frac_valid, frac_test, seed, log_every_n) and returns: train_idxs,  valid_idxs,  test_idxs