-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.py
44 lines (34 loc) · 1.12 KB
/
helper.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
import numpy as np
################################################
# Additional Helper Fucntions
################################################
class OneHotEncoder():
def __init__(self):
pass
def fit(self, y, num_classes):
self.y = y
self.num_classes = num_classes
def transform(self):
transformed = np.zeros((self.num_classes, self.y.size))
for col,row in enumerate(self.y):
transformed[row, col] = 1
return transformed
def fit_transform(self, y, num_classes):
self.fit(y, num_classes)
return self.transform()
def inverse_transform(self, y):
# Assumes direct correation between the position and class number
y_class = np.argmax(y, axis=0)
return y_class
class MinMaxScaler():
def __init__(self):
pass
def fit(self, X):
self.min = np.min(X, axis=0)
self.max = np.max(X, axis=0)
def transform(self, X):
transformed = (X - self.min)/(self.max-self.min)
return transformed
def fit_transform(self, X):
self.fit(X)
return self.transform(X)