-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transform.py
46 lines (34 loc) · 1.66 KB
/
Transform.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
import numpy as np
from scipy import stats
class Transform:
def __init__(self, dataset):
# Initialize the Transform class with the raw data.
self.dataset = sorted(dataset)
# Basic Statistic Variable
self.mean = np.mean(dataset)
self.std = np.std(dataset)
self.min_value = np.min(dataset)
self.max_value = np.max(dataset)
self.length = len(dataset)
self.lambda_value = None
self.transformed_data = [] # Store transformed data here
def logaritmic(self):
self.transformed_data = [np.log10(x) for x in self.data]
def sqrt_root(self):
self.transformed_data = [np.sqrt(x) for x in self.data]
def power_two(self):
self.transformed_data = [x**2 for x in self.dataset]
def reciprocal(self):
self.transformed_data = [1 / (x + 1e-9) for x in self.dataset]
def z_score(self):
self.transformed_data = [(x - self.mean) / self.std for x in self.dataset]
def min_max(self):
self.transformed_data = [(x - self.min_value) / (self.max_value - self.min_value) for x in self.dataset]
def boxcox(self):
self.transformed_data, self.lambda_value = stats.boxcox([x for x in self.data if x > 0]) # Box-Cox hanya untuk data positif
self.transformed_data = self.transformed_data.tolist() # Mengonversi hasil ke list
def logit(self):
self.transformed_data = [np.log(x / (1 - x + 1e-9)) for x in self.dataset] # Menambahkan epsilon untuk menghindari log(0)
def yeo_johnshon(self):
self.transformed_data = stats.yeojohnson(self.dataset)
self.transformed_data = self.transformed_data.tolist()