alex3465
alex3465

Reputation: 419

Windowed Min-max transformation

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

Answers (1)

mozway
mozway

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()

input data

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()

output data

Same on non-noisy data

input:

non-noisy input

output:

non-noisy output

Upvotes: 1

Related Questions