本文整理汇总了Python中file.File.write_json方法的典型用法代码示例。如果您正苦于以下问题:Python File.write_json方法的具体用法?Python File.write_json怎么用?Python File.write_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.write_json方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enumerate
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import write_json [as 别名]
for j, candidate in enumerate(training_with_label):
dist = DTW.dist(data, candidate['data'])
if dist < min_dist:
min_dist = dist
min_pos = j
predicted = training_with_label[min_pos]['label']
if predicted == label:
correctness += 1
print('min_dist:', min_dist)
print('min_pos:', min_pos)
print('predicted label:', predicted)
print('actual label:', label)
print('correctness:', correctness)
print('accuracy:', correctness / len(testing) * 100)
result['dtw'] = {
"correctness": correctness,
"total": len(testing),
'accuracy': correctness / len(testing) * 100
}
# write to file
File.write_json('Coffee.json', result)
示例2: enumerate
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import write_json [as 别名]
"train": File.open_with_label("Beef_TRAIN"),
"test": File.open_with_label("Beef_TEST"),
"fn": two_sym_fn,
},
{
"title": "Beef.P=2.asym",
"train": File.open_with_label("Beef_TRAIN"),
"test": File.open_with_label("Beef_TEST"),
"fn": two_asym_fn,
},
]
for i, job in enumerate(jobs):
print("job:", i, "of", len(jobs))
print("job:", job["title"])
result = {"title": job["title"]}
start_time = time.process_time()
accuracy, correctness = DTW.predict_list(job["train"], job["test"], job["fn"])
end_time = time.process_time()
result["accuracy"] = accuracy
result["correctness"] = correctness
result["total"] = len(job["test"])
result["time_elapsed"] = end_time - start_time
File.write_json(job["title"] + ".json", result)
示例3: print
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import write_json [as 别名]
print('c:', c)
start_time = time.process_time()
accuracy, correctness = DTW.predict_list(job['train'], job['test'], [a, b, c], [ [-1, 0], [0, -1], [-1, -1] ])
print('[', a, b, c, ']', 'accuracy:', accuracy, 'correctness:', correctness)
end_time = time.process_time()
time_elasped = end_time - start_time
print('time_elapsed:', time_elasped)
result = {
'a': a,
'b': b,
'c': c,
'accuracy': accuracy,
'correctness': correctness,
'total': len(job['test']),
'time_elapsed': time_elasped
}
results['results'].append(result)
end_time = time.process_time()
results['time_elapsed'] = end_time - start_time
File.write_json(job['title'] + '.json', results)