-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_data.py
128 lines (80 loc) · 3.31 KB
/
load_data.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
123
124
125
126
127
128
import numpy as np
import pandas as pd
# segmentation dataset
def load_segmentation_dataset():
path_train = "./segmentation/segmentation.data"
path_test = "./segmentation/segmentation.test"
data_train = np.array(pd.read_csv(path_train, header=None, delimiter=","))
data_test = np.array(pd.read_csv(path_test, header=None, delimiter=","))
data = np.vstack((data_train, data_test))
data_y, data_x = data[:, 0], data[:, 1:]
classes = np.unique(data_y)
dic_str_to_int = dict(zip(classes, np.arange(0, len(classes), 1)))
data_y = [dic_str_to_int[string] for string in data_y]
return data_x, np.array(data_y)
def load_winequality_dataset():
path_red_wine = "./wine_quality/winequality-red.csv"
path_white_wine = "./wine_quality/winequality-white.csv"
data_red = pd.read_csv(path_red_wine, delimiter=";")
data_white = pd.read_csv(path_white_wine, delimiter=";")
data = np.vstack((data_red, data_white))
data_x = data[:, :-1]
data_y = [0] * data_red.shape[0] + [1] * data_white.shape[0]
return data_x, np.array(data_y)
def load_credit_dataset():
path = "./credit/credit.data"
data = np.array(pd.read_csv(path, header=None, delimiter=","))
data_list = []
for index in range(data.shape[0]):
row = [float(value) for value in data[index][0].split(" ") if value.isnumeric()]
data_list.append(row)
data_list = np.array(data_list)
data_x = data_list[:, :-1]
data_y = data_list[:, -1] - 1
return data_x, data_y
def load_observatory_dataset():
path = "./observatory/observatory.data"
data = np.array(pd.read_csv(path, delimiter=","))
data_y, data_x = data[:, -1], data[:, :-1]
classes = np.unique(data_y)
dic_str_to_int = dict(zip(classes, np.arange(0, len(classes), 1)))
data_y = [dic_str_to_int[string] for string in data_y]
return data_x, np.array(data_y)
def load_ionosphere_dataset():
path = "./ionosphere/ionosphere.data"
data = np.array(pd.read_csv(path, delimiter=","))
data_y, data_x = data[:, -1], data[:, :-1]
return data_x, data_y
def load_wine_dataset():
path = "./wine/wine.data"
data = np.array(pd.read_csv(path, delimiter=","))
data_y, data_x = data[:, 0], data[:, 1:]
return data_x, data_y
def load_libras_dataset():
path = "./movement_libras/movement_libras.data"
data = np.array(pd.read_csv(path, delimiter=","))
data_y, data_x = data[:, -1], data[:, :-1]
return data_x, data_y
def shuffle_data(x_data, y_data, seed):
np.random.seed(seed)
shuffle_list = np.arange(x_data.shape[0])
np.random.shuffle(shuffle_list)
x_data = x_data[shuffle_list]
y_data = y_data[shuffle_list]
return x_data, y_data
def load_data(dataset):
if dataset == "winequality":
data_x, data_y = load_winequality_dataset()
elif dataset == "credit":
data_x, data_y = load_credit_dataset()
elif dataset == "segmentation":
data_x, data_y = load_segmentation_dataset()
elif dataset == "observatory":
data_x, data_y = load_observatory_dataset()
elif dataset == "ionosphere":
data_x, data_y = load_ionosphere_dataset()
elif dataset == "wine":
data_x, data_y = load_wine_dataset()
elif dataset == "libras":
data_x, data_y = load_libras_dataset()
return data_x, data_y