Skip to content

Commit

Permalink
refactor(frontend): simplify train_size and test_size derivation in t…
Browse files Browse the repository at this point in the history
…est_train_split function
  • Loading branch information
Ishticode committed Aug 27, 2023
1 parent 610413d commit a88c50d
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions ivy/functional/frontends/sklearn/model_selection/_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,15 @@ def train_test_split(*arrays, test_size=None, train_size=None, random_state=None
# TODO: implement stratify
if stratify is not None:
raise NotImplementedError
n_arrays = len(arrays)
if n_arrays == 0:
if len(arrays) == 0:
raise ValueError("At least one array required as input")
if test_size is None and train_size is None:
test_size = 0.25
n_samples = arrays[0].shape[0]
test_size_type, train_size_type = type(test_size), type(train_size)
if "f" in str(test_size_type):
n_test = ivy.ceil(test_size * n_samples)
elif "i" in str(test_size_type):
n_test = float(test_size)
else:
n_test = 0

if "f" in str(train_size_type):
n_train = ivy.floor(train_size * n_samples)
elif "i" in str(train_size_type):
n_train = float(train_size)
else:
n_train = 0

n_train = ivy.floor(train_size * n_samples) if isinstance(train_size, float) \
else float(train_size) if isinstance(train_size, int) else None
n_test = ivy.ceil(test_size * n_samples) if isinstance(test_size, float) \
else float(test_size) if isinstance(test_size, int) else None
if train_size is None:
n_train = n_samples - n_test
elif test_size is None:
Expand Down

0 comments on commit a88c50d

Please sign in to comment.