def __call__(self, X, y, net):
if self.eval_size is not None:
if net.regression or not self.stratify:
# test_size = self.eval_size
# kf = ShuffleSplit(
# y.shape[0], test_size=test_size,
# random_state=self.random_state
# )
# train_indices, valid_indices = next(iter(kf))
# valid_indices = shuffle(valid_indices)
test_size = 1 - self.eval_size
kf = ShuffleSplit(
y.shape[0], test_size=test_size,
random_state=self.random_state
)
valid_indices, train_indices = next(iter(kf))
else:
n_folds = int(round(1 / self.eval_size))
kf = StratifiedKFold(y, n_folds=n_folds, random_state=self.random_state)
train_indices, valid_indices = next(iter(kf))
X_train, y_train = X[train_indices], y[train_indices]
X_valid, y_valid = X[valid_indices], y[valid_indices]
else:
X_train, y_train = X, y
X_valid, y_valid = X[len(X):], y[len(y):]
return X_train, X_valid, y_train, y_valid
评论列表
文章目录