-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
[mypy] | ||
disable_error_code = annotation-unchecked | ||
|
||
[mypy-sklearn.*] | ||
; TechDebt: Should implement typings | ||
ignore_missing_imports = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/synnax_shared/data_processing/scaler/min_max_scaler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import TypedDict | ||
from pandas import Series | ||
|
||
|
||
class MinMaxScalerDto(TypedDict): | ||
min: float | ||
max: float | ||
|
||
|
||
class MinMaxScaler: | ||
|
||
def __init__(self, min: float | None = None, max: float | None = None): | ||
self.min = min | ||
self.max = max | ||
|
||
def fit_transform(self, series: Series) -> Series: | ||
self.min = series.min() | ||
self.max = series.max() | ||
return self.transform(series) | ||
|
||
def transform(self, series: Series) -> Series: | ||
if self.min is None or self.max is None: | ||
raise ValueError("MinMaxScaler not fitted") | ||
series = series.copy() | ||
return (series - self.min) / (self.max - self.min) | ||
|
||
def inverse_transform(self, series: Series) -> Series: | ||
if self.min is None or self.max is None: | ||
raise ValueError("MinMaxScaler not fitted") | ||
series = series.copy() | ||
return series * (self.max - self.min) + self.min | ||
|
||
def toDto(self) -> MinMaxScalerDto: | ||
if self.min is None or self.max is None: | ||
raise ValueError("MinMaxScaler not fitted") | ||
return {"min": self.min, "max": self.max} | ||
|
||
@staticmethod | ||
def fromDto(dto: MinMaxScalerDto): | ||
return MinMaxScaler(dto["min"], dto["max"]) |