Skip to content

Commit

Permalink
init PredefinedMinMaxScaler
Browse files Browse the repository at this point in the history
  • Loading branch information
DanilZherebtsov committed Aug 30, 2024
1 parent 55cfd84 commit 7411a18
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/synnax_shared/data_processing/scaler/PredefinedMinMaxScaler
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pandas as pd

class PredefinedMinMaxScaler:
'''Scaler that scales data to the user defined range [min_val, max_val]'''
def __init__(self, min_val: float, max_val: float) -> None:
self.min_val = min_val
self.max_val = max_val

def scale_column(
self, column: pd.Series, min_val: float, max_val: float
) -> pd.Series:
return (column - min_val) / (max_val - min_val)

def unscale_column(
self, column: pd.Series, min_val: float, max_val: float
) -> pd.Series:
return column * (max_val - min_val) + min_val

def transform(self, data: pd.DataFrame) -> pd.DataFrame:
data = data.copy()
for column in data.select_dtypes(include=[np.number]):
data[column] = self.scale_column(data[column], self.min_val, self.max_val)
return data

def inverse_transform(self, data: pd.DataFrame) -> pd.DataFrame:
data = data.copy()
for column in data.select_dtypes(include=[np.number]):
data[column] = self.unscale_column(data[column], self.min_val, self.max_val)
return data

0 comments on commit 7411a18

Please sign in to comment.