-
Notifications
You must be signed in to change notification settings - Fork 1
/
Data.py
159 lines (116 loc) · 4.47 KB
/
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 2 18:58:44 2018
@author: Tobias Schwedes
Script to load data for logistic Bayesian regression problems.
"""
import numpy as np
class DataLoad:
def __init__(self, case):
if case == "ripley":
# Two hyperparameters of model
Polynomial_Order = 1
# Load and prepare Train and Test Data
X = np.loadtxt("./Data/ripley.txt")
self.t = X[:, -1]
X = X[:, :-1]
self.m = X.shape[0]
# Standardise Data
X = (X - np.tile(np.mean(X, axis=0), (self.m, 1))) / np.tile(
np.std(X, axis=0, ddof=1), (self.m, 1)
)
# Create Polynomial Basis
self.XX = np.ones((self.m, 1))
for i in range(Polynomial_Order + 1)[1:]:
self.XX = np.concatenate((self.XX, X**i), axis=1)
[self.m, self.d] = self.XX.shape
elif case == "pima":
# Two hyperparameters of model
Polynomial_Order = 1
# Load and prepare Train and Test Data
X = np.loadtxt("./Data/pima.txt")
self.t = X[:, -1]
X = X[:, :-1]
self.m = X.shape[0]
# Standardise Data
X = (X - np.tile(np.mean(X, axis=0), (self.m, 1))) / np.tile(
np.std(X, axis=0, ddof=1), (self.m, 1)
)
# Create Polynomial Basis
self.XX = np.ones((self.m, 1))
for i in range(Polynomial_Order + 1)[1:]:
self.XX = np.concatenate((self.XX, X**i), axis=1)
[self.m, self.d] = self.XX.shape
elif case == "german":
# Two hyperparameters of model
Polynomial_Order = 1
# Load and prepare Train and Test Data
X = np.loadtxt("./Data/german.txt")
self.t = X[:, -1]
X = X[:, :-1]
self.m = X.shape[0]
# Replace all 1s in t with 0s
self.t[self.t == 1] = 0
# Replace all 2s in t with 1s
self.t[self.t == 2] = 1
# Standardise Data
X = (X - np.tile(np.mean(X, axis=0), (self.m, 1))) / np.tile(
np.std(X, axis=0, ddof=1), (self.m, 1)
)
# Create Polynomial Basis
self.XX = np.ones((self.m, 1))
for i in range(Polynomial_Order + 1)[1:]:
self.XX = np.concatenate((self.XX, X**i), axis=1)
[self.m, self.d] = self.XX.shape
elif case == "heart":
# Two hyperparameters of model
Polynomial_Order = 1
# Load and prepare Train and Test Data
X = np.loadtxt("./Data/heart.txt")
self.t = X[:, -1]
X = X[:, :-1]
self.m = X.shape[0]
# Replace all 1s in t with 0s
self.t[self.t == 1] = 0
# Replace all 2s in t with 1s
self.t[self.t == 2] = 1
# Standardise Data
X = (X - np.tile(np.mean(X, axis=0), (self.m, 1))) / np.tile(
np.std(X, axis=0, ddof=1), (self.m, 1)
)
# Create Polynomial Basis
self.XX = np.ones((self.m, 1))
for i in range(Polynomial_Order + 1)[1:]:
self.XX = np.concatenate((self.XX, X**i), axis=1)
[self.m, self.d] = self.XX.shape
elif case == "australian":
# Two hyperparameters of model
Polynomial_Order = 1
# Load and prepare Train and Test Data
X = np.loadtxt("./Data/australian.txt")
self.t = X[:, -1]
X = X[:, :-1]
self.m = X.shape[0]
# Standardise Data
X = (X - np.tile(np.mean(X, axis=0), (self.m, 1))) / np.tile(
np.std(X, axis=0, ddof=1), (self.m, 1)
)
# Create Polynomial Basis
self.XX = np.ones((self.m, 1))
for i in range(Polynomial_Order + 1)[1:]:
self.XX = np.concatenate((self.XX, X**i), axis=1)
[self.m, self.d] = self.XX.shape
else:
raise ValueError(
"case must be chosen from one of the following: 'ripley',\
'pima', 'heart', 'australian', 'german'"
)
def GetDimension(self):
return self.d
def GetDesignMatrix(self):
return self.XX
def GetNumOfSamples(self):
return self.m
def GetResponses(self):
return self.t