-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprocess.py
78 lines (67 loc) · 2.49 KB
/
process.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from sklearn.preprocessing import LabelEncoder
import json
def predo(data):
s = (data.dtypes == 'object')
object_cols = list(s[s].index)
pre_data = data.copy()
label_encoder = LabelEncoder()
for col in object_cols:
pre_data[col] = label_encoder.fit_transform(data[col])
# age 和gender需要进一步划分成二分类
# 对于 german age划分以45岁为标准
#todo 其他数据
pre_data[12][pre_data[12] <= 45] = 0
pre_data[12][pre_data[12] > 45]= 1
pre_data[8][pre_data[8] == 2] = 0 # male
pre_data[8][pre_data[8] == 3] = 0 # male
pre_data[8][pre_data[8] == 5] = 1 # female
return pre_data.values.tolist()
def predo_tra(data):
s = (data.dtypes == 'object')
object_cols = list(s[s].index)
pre_data = data.copy()
label_encoder = LabelEncoder()
for col in object_cols:
pre_data[col] = label_encoder.fit_transform(data[col])
# age 和gender需要进一步划分成二分类
# 对于 german age划分以45岁为标准
#todo 其他数据
pre_data[9][pre_data[9] <= 45] = 0
pre_data[9][pre_data[9] > 45]= 1
return pre_data.values.tolist()
def preres(data, path):
res_data = data
with open(path, 'r', encoding='utf-8') as file:
file_json = json.load(file)
for i, text in enumerate(file_json):
if text['truth']=='good' and text['acc']=='1.0':
res_data[i][-1] = 1
elif text['truth']=='bad' and text['acc']=='0.0':
res_data[i][-1] = 1
else: res_data[i][-1] = 2
return res_data
def preres_tra(data, path):
res_data = data
with open(path, 'r', encoding='utf-8') as file:
file_json = json.load(file)
for i, text in enumerate(file_json):
if text['truth']=='no' and text['acc']=='1.0':
res_data[i][0] = 0
elif text['truth']=='yes' and text['acc']=='0.0':
res_data[i][0] = 0
else: res_data[i][0] = 1
return res_data
def preres_cc(data, path):
res_data = data
with open(path, 'r', encoding='utf-8') as file:
file_json = json.load(file)
index = []
for i, text in enumerate(file_json):
if text['missing']=='1':
index.append(i)
elif text['truth']=='good' and text['acc']=='1.0':
res_data[i][-1] = 0
elif text['truth']=='bad' and text['acc']=='0.0':
res_data[i][-1] = 0
else: res_data[i][-1] = 1
return res_data,index