original_docstring: Split a dataset so that the ratio of classes in the test set equals to the train set.
      Also returns item counts per classes
docstring: Split a dataset so that the ratio of classes in the test set equals to the train set.
  Also returns item counts per classes
docstring_tokens: Split a dataset so that the ratio of classes in the test set equals to the train set . Also returns item counts per classes
code: def constant_ratio_split(items: List[MushroomImage], classnames: List[str],
                          ratio: float) -> Tuple[List[int], List[int], List[int], List[int]]:
      """Split a dataset so that the ratio of classes in the test set equals to the train set.
      Also returns item counts per classes"""
  
      # Build a list of lists from the item indices
      classes = [[] for i in range(len(classnames))]
      for i, item in enumerate(items):
          classes[item.class_id].append(i)
  
      # Shuffle and split each class list
      train_idx = []
      train_counts = []
      test_idx = []
      test_counts = []
      for cls in classes:
          np.random.shuffle(cls)
          split_idx = int(len(cls) * ratio)
          train_idx += cls[:split_idx]
          train_counts.append(len(cls[:split_idx]))
          test_idx += cls[split_idx:]
          test_counts.append(len(cls[split_idx:]))
  
      # Shuffle again for good measure, in case the dataloader doesn't
      np.random.shuffle(train_idx)
      np.random.shuffle(test_idx)
  
      return train_idx, train_counts, test_idx, test_counts
code_tokens: def constant_ratio_split ( items : List [ MushroomImage ] , classnames : List [ str ] , ratio : float ) -> Tuple [ List [ int ] , List [ int ] , List [ int ] , List [ int ] ] : classes = [ [ ] for i in range ( len ( classnames ) ) ] for i , item in enumerate ( items ) : classes [ item . class_id ] . append ( i ) train_idx = [ ] train_counts = [ ] test_idx = [ ] test_counts = [ ] for cls in classes : np . random . shuffle ( cls ) split_idx = int ( len ( cls ) * ratio ) train_idx += cls [ : split_idx ] train_counts . append ( len ( cls [ : split_idx ] ) ) test_idx += cls [ split_idx : ] test_counts . append ( len ( cls [ split_idx : ] ) ) np . random . shuffle ( train_idx ) np . random . shuffle ( test_idx ) return train_idx , train_counts , test_idx , test_counts
short_docstring: Split a dataset so that the ratio of classes in the test set equals to the train set.
short_docstring_tokens: Split a dataset so that the ratio of classes in the test set equals to the train set .
comment: """Split a dataset so that the ratio of classes in the test set equals to the train set.
      Also returns item counts per classes"""$SEP$# Build a list of lists from the item indices$SEP$# Shuffle and split each class list$SEP$# Shuffle again for good measure, in case the dataloader doesn't