-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_dataframe.py
More file actions
43 lines (29 loc) · 1.32 KB
/
Copy pathsplit_dataframe.py
File metadata and controls
43 lines (29 loc) · 1.32 KB
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
42
43
import random
import math
# Splitting dataframes
def split_matrix_random(cl, feat):
# Selecting 4 casual rows
ind = random.sample(range(len(feat)), math.ceil(len(feat)*0.7))
#print(ind)
tr_feat = [feat[i] for i in ind]
tr_cl = [cl[i] for i in ind]
test_feat = [feat[i] for i in range(len(feat)) if i not in ind]
test_cl = [cl[i] for i in range(len(feat)) if i not in ind]
cleaned_tr_feat = [row.tolist() for row in tr_feat]
cleaned_test_feat = [row.tolist() for row in test_feat]
cleaned_tr_cl = [float(row) for row in tr_cl]
cleaned_test_cl = [float(row) for row in test_cl]
return cleaned_tr_cl, cleaned_tr_feat, cleaned_test_cl, cleaned_test_feat
def split_matrix(cl, feat):
# Selecting specific rows
ind = list(range(0, 47)) + list(range(99, 177))
#print(ind)
tr_feat = [feat[i] for i in ind]
tr_cl = [cl[i] for i in ind]
test_feat = [feat[i] for i in range(len(feat)) if i not in ind]
test_cl = [cl[i] for i in range(len(feat)) if i not in ind]
cleaned_tr_feat = [row.tolist() for row in tr_feat]
cleaned_test_feat = [row.tolist() for row in test_feat]
cleaned_tr_cl = [float(row) for row in tr_cl]
cleaned_test_cl = [float(row) for row in test_cl]
return cleaned_tr_cl, cleaned_tr_feat, cleaned_test_cl, cleaned_test_feat