Reputation: 419
Is there any easy way to perform min-max Transformation in a window of lets say 2000 sample point rather on whole data?
np.shape(X)
(10278, 4)
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
X_norm = scaler.fit_transform(X)
Upvotes: 0
Views: 510
Reputation: 260455
I am curious of the pertinence of a min/max scaling using a rolling window. I believe this should introduce noise and/or artifacts as each window will be susceptible to the bounds.
Nevertheless, if I understood correctly, here is a way to achieve it:
input test data:
df = pd.DataFrame(np.sin(np.arange(2000)/100+np.arange(4)[:, None])+np.random.normal(scale=0.2, size=(4,2000))).T
df.plot.line()
min/max scaled data:
df_scaled = df.rolling(window=40, min_periods=1).apply(lambda a: ((a.iloc[0]-a.min())/(a.max()-a.min())))
df_scaled.plot.line()
input:
output:
Upvotes: 1