如何在python中从字典输出中组装用于监督分类的时间序列数据

问题描述 投票:0回答:2

有人可以帮帮我!我有一个带键和值的字典。每个键都是一个簇标签,与键相关的值是该簇中的数据点。每个数据点是一个包含60列的列表(即一个长度为60的时间序列数据)我希望将这些时间序列逐行汇总以进行监督分类,以便每个时间序列数据点都将键(例如0)作为其行中的最后一个值作为其类。(例如:0.1,0.3,0.5,0 )最后一个零值是类值。这是我真实数据的一部分。

    {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]])}

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

python-2.7 python-3.x classification supervised-learning
2个回答
0
投票

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

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

0
投票

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)

Writes Data to a text file without the bracket each point on a line with

its cluster label as the last point.

使用open('mytest.txt','w')作为outfile:

for item in data_cluster:

    outfile.write("%s\n" % ','.join(map(str,item)))
© www.soinside.com 2019 - 2024. All rights reserved.