Base class for all scalers, implementing common methods.
Source code in sorix/preprocessing/scalers.py
| def __init__(self):
self.numerical_features: List[str] = []
self.n_features: int = 0
|
prepros
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
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
|