assemble 如何从 python 中的字典输出中 assemble 时间序列数据进行监督分类

How to assemble time series data for supervised classification from dictionary output in python

有人能帮帮我吗! 我有一个带键的字典,values.Each 键是一个集群标签,与键关联的值是其中的数据点 cluster.Each 数据点是一个包含 60 列的列表(即时间序列长度为 60 的数据)。我想 assemble 这些时间序列按行进行监督 class 化,这样每个时间序列数据点都将键(比如 0)作为行中的最后一个值它的 class.(例如:0.1,0.3,0.5, 0)其中最后一个零值是 class 值。这是我的部分真实数据。

    {0: array([[ 28.7812,  34.4632,  31.3381, ...,  33.3759,  25.4652,  25.8717],

    [ 24.8923,  25.741 ,  27.5532, ...,  34.2484,  32.1005,  26.691 ],

    [ 31.3987,  30.6316,  26.3983, ...,  33.9002,  29.5446,  29.343 ],
    ..., 
    [ 24.4293,  39.7616,  40.1207, ...,  42.3223,  31.9421,  32.8973],

    [ 32.3175,  39.9719,  40.6855, ...,  28.8281,  41.7112,  35.3453],

    [ 25.7836,  34.1285,  42.6593, ...,  34.4315,  32.155 ,  34.8388]]),

   {1: array([[ 35.7709,  34.396 ,  35.2249, ...,  32.4859,  30.7772,  24.5854],

    [ 24.9706,  33.8315,  46.9423, ...,  24.1889,  11.4137,  13.1961],

    [ 35.5351,  41.7067,  39.1705, ...,  37.7721,  37.2248,  32.9494],
    ..., 
    [ 28.0747,  41.7835,  42.1198, ...,  38.0344,  46.4582,  44.4323],

    [ 33.6696,  38.6754,  39.7419, ...,  34.9395,  36.9095,  39.7494],

    [ 30.5729,  41.0741,  44.9793, ...,  24.353 ,  19.7201,  12.7513]])}

简单来说,我只对不带括号的每一行的值感兴趣,然后将其附加到该行,并将其键作为行中的最后一个数字。

我不确定我的输入格式是否正确...

input = {0: [['0', '0']], 1: [['0', '0']]}
output = []
for key in input.keys():
    input[key].append(key)
    output.append(input[key])

old_cluster = []

对于范围内的 i (0,len(toy_data)):

d_cluster =np.append(toy_data[i], int(labels[i]))

f_cluster= d_cluster.tolist()

old_cluster.append(f_cluster)

data_cluster=np.asarray(old_cluster)

将数据写入不带括号的文本文件,每一点都在

一行

它的簇标签作为最后一个点。

with open('mytest.txt','w') as outfile:

for item in data_cluster:

    outfile.write("%s\n" % ','.join(map(str,item)))