-
Notifications
You must be signed in to change notification settings - Fork 47
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
1 parent
5bb9f59
commit c3ade11
Showing
3 changed files
with
80 additions
and
2 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
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
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,37 @@ | ||
"""Scaling utilities.""" | ||
|
||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import TYPE_CHECKING, Literal, TypeAlias | ||
|
||
if TYPE_CHECKING: | ||
from sklearn.base import BaseEstimator, TransformerMixin | ||
|
||
Scaler: TypeAlias = BaseEstimator | TransformerMixin | ||
|
||
|
||
class ScalingMethod(Enum): | ||
"""Available scaling methods.""" | ||
|
||
IDENTITY = "IDENTITY" | ||
"""Identity transformation (no scaling applied).""" | ||
|
||
MINMAX = "MINMAX" | ||
"""Min-max scaling, mapping the observed value range to [0, 1].""" | ||
|
||
MAXABS = "MAXABS" | ||
"""Max-abs scaling, scaling by the largest observed absolute (applies no shift).""" | ||
|
||
|
||
def make_scaler(method: ScalingMethod, /) -> Scaler | Literal["passthrough"]: | ||
"""Create a scaler object based on the specified method.""" | ||
from sklearn.preprocessing import MaxAbsScaler, MinMaxScaler | ||
|
||
match method: | ||
case ScalingMethod.IDENTITY: | ||
return "passthrough" | ||
case ScalingMethod.MINMAX: | ||
return MinMaxScaler() | ||
case ScalingMethod.MAXABS: | ||
return MaxAbsScaler() |