【发布时间】:2019-03-11 21:45:51
【问题描述】:
对于形状为(num_samples,features) 的数据,可以使用来自sklearn.preprocessing 的MinMaxScaler 轻松对其进行归一化。
但是,当对形状为(num_samples, time_steps,features)的时间序列数据使用相同的方法时,sklearn会报错。
from sklearn.preprocessing import MinMaxScaler
import numpy as np
#Making artifical time data
x1 = np.linspace(0,3,4).reshape(-1,1)
x2 = np.linspace(10,13,4).reshape(-1,1)
X1 = np.concatenate((x1*0.1,x2*0.1),axis=1)
X2 = np.concatenate((x1,x2),axis=1)
X = np.stack((X1,X2))
#Trying to normalize
scaler = MinMaxScaler()
X_norm = scaler.fit_transform(X) <--- error here
ValueError: 找到暗淡为 3 的数组。MinMaxScaler 应为
这个post 建议类似
(timeseries-timeseries.min())/(timeseries.max()-timeseries.min())
然而,它只适用于只有 1 个特征的数据。由于我的数据具有超过 1 个特征,因此此方法不起作用。
如何对具有多个特征的时间序列数据进行归一化?
【问题讨论】: