-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnew3.py
49 lines (44 loc) · 1.52 KB
/
new3.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
import os
import arff
import math
import smote
import borderline1
import borderline
import adasyn
import numpy as np
files = []
data_path = "MDP\\D''\\"
for f in os.listdir(data_path):
files.append(f)
for f in range(len(files)):
print(f, end="...")
f_path = os.path.join(data_path, files[f])
inst = list(arff.load(f_path))
a = np.array(inst)
size = a.shape
t = math.ceil(0.8*size[0])
print('Smote, ')
res = smote.apply(inst[:t])
path = os.path.join("MDP\\D-smote\\training", files[f])
arff.dump(path, res, relation=files[f][:-5])
path = os.path.join("MDP\\D-smote\\testing", files[f])
arff.dump(path, inst[t:], relation=files[f][:-5])
print('Borderline1, ')
res = borderline1.apply(inst[:t])
path = os.path.join("MDP\\D-bl1\\training", files[f])
arff.dump(path, res, relation=files[f][:-5])
path = os.path.join("MDP\\D-bl1\\testing", files[f])
arff.dump(path, inst[t:], relation=files[f][:-5])
print('Borderline2, ')
res = borderline.apply(inst[:t])
path = os.path.join("MDP\\D-bl2\\training", files[f])
arff.dump(path, res, relation=files[f][:-5])
path = os.path.join("MDP\\D-bl2\\testing", files[f])
arff.dump(path, inst[t:], relation=files[f][:-5])
print('Adasyn')
res = adasyn.apply(inst[:t])
path = os.path.join("MDP\\D-adasyn\\training", files[f])
arff.dump(path, res, relation=files[f][:-5])
path = os.path.join("MDP\\D-adasyn\\testing", files[f])
arff.dump(path, inst[t:], relation=files[f][:-5])
print('...done')