Created
September 5, 2018 08:27
-
-
Save penut85420/ff9a3f9399ed9cf330f69cead659a021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy import concatenate as c | |
x = np.array(range(100)) | |
y = np.array(range(100, 200)) | |
def kfold_split(x, y, sp): | |
seg_len = int(len(x) / sp) | |
for i in range(seg_len): | |
seg_begin = i * seg_len | |
seg_end = (i + 1) * seg_len | |
yield (c([x[:seg_begin], x[seg_end:]]), | |
c([y[:seg_begin], y[seg_end:]]), | |
x[seg_begin:seg_end], | |
y[seg_begin:seg_end]) | |
for x_train, y_train, x_test, y_test in kfold_split(x, y, 10): | |
print('\nxt', x_train, '\nyt', y_train, '\nxs', x_test, '\nys', y_test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment