-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrain_data_converted.py
59 lines (47 loc) · 2.47 KB
/
train_data_converted.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os, sys
import json
train_data = None
with open('train_data.json') as train_data_json:
train_data = json.load(train_data_json)
with open('train_data_converted.txt', 'w') as train_data_text:
if train_data != None:
labels = train_data['labels']
firstLabel = labels[0]
feature_vectors = train_data[firstLabel]
train_data_text.write('{ "' + firstLabel + '", {')
first_feature_vector = feature_vectors[0]
train_data_text.write('\n{')
float_feature_vector = [ float(n) for n in first_feature_vector.split(', ') ]
train_data_text.write(str(float_feature_vector[0]))
for i in range(1, len(float_feature_vector)):
train_data_text.write(',' + str(float_feature_vector[i]))
train_data_text.write('}')
for i in range(1, len(feature_vectors)):
feature_vector = feature_vectors[i]
train_data_text.write(',\n{')
float_feature_vector = [ float(n) for n in feature_vector.split(', ') ]
train_data_text.write(str(float_feature_vector[0]))
for j in range(1, len(float_feature_vector)):
train_data_text.write(',' + str(float_feature_vector[j]))
train_data_text.write('}')
train_data_text.write('}\n}')
labels.remove(firstLabel)
for label in labels:
feature_vectors = train_data[label]
train_data_text.write(',\n{ "' + label + '", {')
first_feature_vector = feature_vectors[0]
train_data_text.write('\n{')
float_feature_vector = [ float(n) for n in first_feature_vector.split(', ') ]
train_data_text.write(str(float_feature_vector[0]))
for i in range(1, len(float_feature_vector)):
train_data_text.write(',' + str(float_feature_vector[i]))
train_data_text.write('}')
for i in range(1, len(feature_vectors)):
feature_vector = feature_vectors[i]
train_data_text.write(',\n{')
float_feature_vector = [ float(n) for n in feature_vector.split(', ') ]
train_data_text.write(str(float_feature_vector[0]))
for j in range(1, len(float_feature_vector)):
train_data_text.write(',' + str(float_feature_vector[j]))
train_data_text.write('}')
train_data_text.write('}\n}')