Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def split_dataset_n(dataset: Dataset,
n: int,
indices: List[int] = None) -> List[SubDataset]:
n_examples = len(dataset)
sub_size = n_examples // n
return [SubDataset(dataset, sub_size * i, sub_size * (i + 1), indices)
for i in range(n)]
def split_dataset_n_random(dataset: Dataset,
n: int,
seed=None) -> List[SubDataset]:
n_examples = len(dataset)
sub_size = n_examples // n
random.seed(seed)
indices = list(range(len(dataset)))
random.shuffle(indices)
return [SubDataset(dataset, sub_size * i, sub_size * (i + 1), indices)
for i in range(n)]
def split_dataset(dataset: Dataset,
split_at: int,
indices: List[int] = None) -> Tuple[SubDataset]:
n_examples = len(dataset)
if not isinstance(split_at, int):
raise TypeError(f'split_at must be int, got {type(split_at)} instead')
if split_at < 0:
raise ValueError('split_at must be non-negative')
if split_at > n_examples:
raise ValueError('split_at exceeds the dataset size')
subset1 = SubDataset(dataset, 0, split_at, indices)
subset2 = SubDataset(dataset, split_at, n_examples, indices)
return subset1, subset2
def split_dataset(dataset: Dataset,
split_at: int,
indices: List[int] = None) -> Tuple[SubDataset]:
n_examples = len(dataset)
if not isinstance(split_at, int):
raise TypeError(f'split_at must be int, got {type(split_at)} instead')
if split_at < 0:
raise ValueError('split_at must be non-negative')
if split_at > n_examples:
raise ValueError('split_at exceeds the dataset size')
subset1 = SubDataset(dataset, 0, split_at, indices)
subset2 = SubDataset(dataset, split_at, n_examples, indices)
return subset1, subset2