-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhold_out.py
41 lines (30 loc) · 1.21 KB
/
hold_out.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
def hold_out(data, percent_to_train):
if percent_to_train > 1:
percent_to_train = percent_to_train/100
split_idx = int(len(data)* (percent_to_train))
neural_train = data[:split_idx]
neural_test = data[split_idx:]
neural_train = np.array(neural_train)
neural_test = np.array(neural_test)
return neural_train, neural_test
'''
def hold_out(data, percent_to_hold):
if percent_to_hold > 1:
percent_to_hold = percent_to_hold / 100
total_length = len(data)
hold_length = int(total_length * percent_to_hold)
# Calculate the start and end indices of the held-out portion
start_hold = int((total_length - hold_length) / 2)
end_hold = start_hold + hold_length
# Split the data into three parts
neural_train_first = data[:start_hold]
neural_test = data[start_hold:end_hold]
neural_train_second = data[end_hold:]
# Concatenate the first and last parts to form the training set
neural_train = np.concatenate((neural_train_first, neural_train_second), axis=0)
# Convert to numpy arrays if not already
neural_train = np.array(neural_train)
neural_test = np.array(neural_test)
return neural_train, neural_test
'''