Skip to content

scalers

sorix.preprocessing.scalers

BaseScaler

BaseScaler()

Base class for all scalers, implementing common methods.

Source code in sorix/preprocessing/scalers.py
7
8
9
def __init__(self):
    self.numerical_features: List[str] = []
    self.n_features: int = 0

prepros

prepros(X)

Validates and registers column names.

Source code in sorix/preprocessing/scalers.py
def prepros(self, X: Union[np.ndarray, pd.DataFrame]):
    """Validates and registers column names."""
    if isinstance(X, pd.DataFrame):
        self.numerical_features = list(X.columns)
        X = X.to_numpy()
    elif isinstance(X, np.ndarray):
        self.numerical_features = [f"F{i}" for i in range(X.shape[1])] if X.ndim > 1 else ["F0"]
    else:
        raise TypeError("Input must be a NumPy ndarray or a Pandas DataFrame.")

    self.n_features = X.shape[1] if X.ndim > 1 else 1
    return X

state_dict

state_dict()

Returns a dictionary with the scaler's state.

Source code in sorix/preprocessing/scalers.py
def state_dict(self):
    """Returns a dictionary with the scaler's state."""
    return {k: v for k, v in self.__dict__.items() if not k.startswith('_')}

load_state_dict

load_state_dict(state_dict)

Loads the scaler's state from a dictionary.

Source code in sorix/preprocessing/scalers.py
def load_state_dict(self, state_dict):
    """Loads the scaler's state from a dictionary."""
    for k, v in state_dict.items():
        setattr(self, k, v)
    return self

MinMaxScaler

MinMaxScaler()

Bases: BaseScaler

Scales features to a range [0, 1].

Source code in sorix/preprocessing/scalers.py
def __init__(self):
    super().__init__()
    self.min: Optional[np.ndarray] = None
    self.max: Optional[np.ndarray] = None

StandardScaler

StandardScaler()

Bases: BaseScaler

Standardizes by removing the mean and scaling to unit variance.

Source code in sorix/preprocessing/scalers.py
def __init__(self):
    super().__init__()
    self.mean: Optional[np.ndarray] = None
    self.std: Optional[np.ndarray] = None

RobustScaler

RobustScaler()

Bases: BaseScaler

Scales using median and IQR (robust to outliers).

Source code in sorix/preprocessing/scalers.py
def __init__(self):
    super().__init__()
    self.median: Optional[np.ndarray] = None
    self.q1: Optional[np.ndarray] = None
    self.q3: Optional[np.ndarray] = None