-
Notifications
You must be signed in to change notification settings - Fork 1
/
preprocessing.py
122 lines (95 loc) · 3.47 KB
/
preprocessing.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
def lymphography_dataset():
path = "./datasets/lymphography.csv"
df = pd.read_csv(path)
df.Label[df.Label == 3] = 0
df.Label[df.Label == 4] = 1
df.Label[df.Label == 1] = 1
df.Label[df.Label == 2] = 0
df_norm = df[df.Label == 0]
df_anom = df[df.Label == 1]
ds_norm = df_norm.values
ds_anom = df_anom.values
X_train = ds_norm[:100, :-1]
Y_train = ds_norm[:100, -1]
l = ds_norm.shape[0] - X_train.shape[0]
no_of_test_samples = l + ds_anom.shape[0]
no_of_features = X_train.shape[1]
X_test = np.zeros((no_of_test_samples, no_of_features))
Y_test = np.zeros((no_of_test_samples,))
X_test[:l, :] = ds_norm[100:, :-1]
X_test[l:, :] = ds_anom[:,:-1]
print(X_test.shape)
Y_test[:l,] = ds_norm[100:, -1]
Y_test[l:,] = ds_anom[:, -1]
return X_train, Y_train, X_test, Y_test, ds_anom, ds_norm
def pageblocks_dataset():
path = "./datasets/page-blocks.csv"
df = pd.read_csv(path)
df.label[df.label == 1] = 0
df.label[df.label == 2] = 1
df.label[df.label == 3] = 1
df.label[df.label == 4] = 1
df.label[df.label == 5] = 1
df_norm = df[df.label == 0]
df_anom = df[df.label == 1]
ds_norm = df_norm.values
ds_anom = df_anom.values
X_train = ds_norm[:4700, :-1]
Y_train = ds_norm[:4700, -1]
l = ds_norm.shape[0] - X_train.shape[0]
no_of_test_samples = l + ds_anom.shape[0]
no_of_features = X_train.shape[1]
X_test = np.zeros((no_of_test_samples, no_of_features))
Y_test = np.zeros((no_of_test_samples,))
X_test[:l, :] = ds_norm[4700:, :-1]
X_test[l:, :] = ds_anom[:,:-1]
print(X_test.shape)
Y_test[:l,] = ds_norm[4700:, -1]
Y_test[l:,] = ds_anom[:, -1]
return X_train, Y_train, X_test, Y_test, ds_anom, ds_norm
def postoperative_dataset():
path = "./datasets/postop.csv"
df = pd.read_csv(path)
df_norm = df[df.Label == 0]
df_anom = df[df.Label == 1]
ds_norm = df_norm.values
ds_anom = df_anom.values
X_train = ds_norm[:50, :-1]
Y_train = ds_norm[:50, -1]
l = ds_norm.shape[0] - X_train.shape[0]
no_of_test_samples = l + ds_anom.shape[0]
no_of_features = X_train.shape[1]
X_test = np.zeros((no_of_test_samples, no_of_features))
Y_test = np.zeros((no_of_test_samples,))
X_test[:l, :] = ds_norm[50:, :-1]
X_test[l:, :] = ds_anom[:,:-1]
print(X_test.shape)
Y_test[:l,] = ds_norm[50:, -1]
Y_test[l:,] = ds_anom[:, -1]
return X_train, Y_train, X_test, Y_test, ds_anom, ds_norm
def cancer_dataset():
path = "./datasets/cancer.csv"
df = pd.read_csv(path)
df.Label[df.Label==1] = 0
df.Label[df.Label==-1] = 1
df_norm = df[df.Label == 0]
df_anom = df[df.Label == 1]
ds_norm = df_norm.values
ds_anom = df_anom.values
X_train = ds_norm[:400, :-1]
Y_train = ds_norm[:400, -1]
l = ds_norm.shape[0] - X_train.shape[0]
no_of_test_samples = l + ds_anom.shape[0]
no_of_features = X_train.shape[1]
X_test = np.zeros((no_of_test_samples, no_of_features))
Y_test = np.zeros((no_of_test_samples,))
X_test[:l, :] = ds_norm[400:, :-1]
X_test[l:, :] = ds_anom[:,:-1]
print(X_test.shape)
Y_test[:l,] = ds_norm[400:, -1]
Y_test[l:,] = ds_anom[:, -1]
return X_train, Y_train, X_test, Y_test, ds_anom, ds_norm