我有时间序列数据帧,我想与卷积神经网络一起用于模式/异常检测。
只是想知道如何在不丢失基本数据的情况下进行转换?
答案 0 :(得分:0)
使用移动窗口从一个简单的数据框中管理形成包含3D阵列的张量,以便在卷积神经网络中进行分析:
def windows(data, size):
start = 0
while start < len(data):
#print(start,start+size)
yield start, start + size
print(start, start + size)
start += 1
def segmentor(data,window_size,num_channels):
segments=np.empty((0,window_size,num_channels)) #create dimensions for height component
for (start,end) in windows(data,window_size):
placeholder=data.iloc[int(start):int(end),:] #slices the dataframe to extract that time window
#Now need to forgo the leftovers in each dataframe:
if(len(placeholder)==window_size): #If the length of timewindow == specified time-window size,
pl_=(np.dstack((placeholder.ix[:,i] for i in placeholder))) #stack the columns (depthwise)
#print(pl_.shape)
#pl_=pl_.swapaxes(1,2)
segments=np.vstack([segments,pl_])
#print(segments.shape)
return segments
然后,可以将生成的结构传递给通用CNN。