from RADAR.base_preprocessing_module import BasePreprocessing
from sklearn.preprocessing import StandardScaler, MinMaxScaler, RobustScaler, Normalizer,OneHotEncoder
import numpy as np
import pandas as pd
[docs]
class StandardScalerPreprocessing(BasePreprocessing):
def __init__(self, **kwargs):
super().__init__()
self.scaler = StandardScaler(**kwargs)
[docs]
def fit(self, X):
self.scaler.fit(X)
return self
[docs]
class MinMaxScalerPreprocessing(BasePreprocessing):
def __init__(self, **kwargs):
super().__init__()
self.scaler = MinMaxScaler(**kwargs)
[docs]
def fit(self, X):
self.scaler.fit(X)
return self
[docs]
class RobustScalerPreprocessing(BasePreprocessing):
def __init__(self, **kwargs):
super().__init__()
self.scaler = RobustScaler(**kwargs)
[docs]
def fit(self, X):
self.scaler.fit(X)
return self
[docs]
class NormalizerPreprocessing(BasePreprocessing):
def __init__(self, **kwargs):
super().__init__()
self.scaler = Normalizer(**kwargs)
[docs]
def fit(self, X):
self.scaler.fit(X)
return self
[docs]
class RollingMeanPreprocessing(BasePreprocessing):
def __init__(self, window=3, **kwargs):
super().__init__(window=window, **kwargs)
self.window = window
[docs]
def fit(self, X):
pass # No requiere ajuste
[docs]
class InterpolationPreprocessing(BasePreprocessing):
def __init__(self, method='linear', **kwargs):
super().__init__(method=method, **kwargs)
self.method = method
[docs]
def fit(self, X):
pass # No requiere ajuste
[docs]
class FilterPreprocessing(BasePreprocessing):
def __init__(self, filter_func=np.mean, kernel_size=3, **kwargs):
super().__init__(filter_func=filter_func, kernel_size=kernel_size, **kwargs)
self.filter_func = filter_func
self.kernel_size = kernel_size
[docs]
def fit(self, X):
pass # No requiere ajuste
[docs]
class OneHotEncoderPreprocessing(BasePreprocessing):
def __init__(self, columns=None, **kwargs):
"""
Parameters
----------
columns : list, optional
List of column names to apply one-hot encoding.
"""
super().__init__()
self.columns = columns
self.encoder = OneHotEncoder(sparse_output=False, handle_unknown="ignore", **kwargs)
self.feature_names = None
[docs]
def fit(self, X):
X_selected = X[self.columns] if self.columns else X
self.encoder.fit(X_selected)
self.feature_names = self.encoder.get_feature_names_out(self.columns)
return self
preprocessing_ts_algorithms = {
"StandardScaler": StandardScalerPreprocessing,
"MinMaxScaler": MinMaxScalerPreprocessing,
"RobustScaler": RobustScalerPreprocessing,
"Normalizer": NormalizerPreprocessing,
"RollingMean": RollingMeanPreprocessing,
"Interpolation": InterpolationPreprocessing,
"Filter": FilterPreprocessing,
"OneHotEncoder": OneHotEncoderPreprocessing
}