mirror of
https://github.com/Doctorado-ML/Stree_datasets.git
synced 2025-08-15 23:46:03 +00:00
Fix normalization & standard. columnwise
This commit is contained in:
@@ -35,23 +35,39 @@ class Dataset_Base:
|
||||
"""
|
||||
pass
|
||||
|
||||
def normalize(self, data: np.array) -> np.array:
|
||||
@staticmethod
|
||||
def normalize(data: np.array) -> np.array:
|
||||
min_data = data.min()
|
||||
return (data - min_data) / (data.max() - min_data)
|
||||
|
||||
def standardize(self, data: np.array) -> np.array:
|
||||
@staticmethod
|
||||
def normalize_rows(data: np.array) -> np.array:
|
||||
res = data.copy()
|
||||
for col in range(res.shape[1]):
|
||||
res[:, col] = Dataset_Base.normalize(res[:, col])
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def standardize(data: np.array) -> np.array:
|
||||
return (data - data.mean()) / data.std()
|
||||
|
||||
@staticmethod
|
||||
def standardize_rows(data: np.array) -> np.array:
|
||||
res = data.copy()
|
||||
for col in range(res.shape[1]):
|
||||
res[:, col] = Dataset_Base.standardize(res[:, col])
|
||||
return res
|
||||
|
||||
def get_params(self) -> str:
|
||||
return f"normalize={self._normalize}, standardize={self._standardize}"
|
||||
|
||||
def post_process(self, X: np.array, y: np.array) -> tdataset:
|
||||
if self._standardize and self._normalize:
|
||||
X = self.standardize(self.normalize(X))
|
||||
X = self.standardize_rows(self.normalize_rows(X))
|
||||
elif self._standardize:
|
||||
X = self.standardize(X)
|
||||
X = self.standardize_rows(X)
|
||||
elif self._normalize:
|
||||
X = self.normalize(X)
|
||||
X = self.normalize_rows(X)
|
||||
return X, y
|
||||
|
||||
def __iter__(self) -> Diterator:
|
||||
|
Reference in New Issue
Block a user