如何使用python解析输出?

时间:2018-05-23 10:46:44

标签: python metrics

我有输入文件,如下所示:

name: "locations/us-east"
classification_metrics {
  au_prc: 1.0
  base_au_prc: 0.20000000298
  evaluated_examples_count: 5
  confidence_metrics_entry {
    recall: 1.0
    precision: -1.73472347598e-18
    f1_score: -3.46944695195e-18
    recall_at1: 1.0
    precision_at1: 1.0
    f1_score_at1: 1.0
  }
  confidence_metrics_entry {
    confidence_threshold: 0.10000000149
    recall: 1.0
    precision: 0.178000003099
    f1_score: 0.302207142115
    recall_at1: 1.0
    precision_at1: 1.0
    f1_score_at1: 1.0
  }
  confusion_matrix {
    row {
      example_count: 1
      example_count: 0
      example_count: 0
      example_count: 0
      example_count: 0
    }
    row {
      example_count: 0
      example_count: 1
      example_count: 0
      example_count: 0
      example_count: 0
    }
  }
}
create_time {
  seconds: 1526971489
  nanos: 307150000
}

name: "locations/us-east"
annotation_spec_id: "locations/us-central1"
classification_metrics {
  au_prc: 1.0
  base_au_prc: 0.20000000298
  confidence_metrics_entry {
    recall: 1.0
  }
  confidence_metrics_entry {
    confidence_threshold: 0.00999999977648
    recall: 1.0
    precision: 0.0143612474203
    f1_score: 0.0283158440143
  }
  confidence_metrics_entry {
    confidence_threshold: 0.019999999553
    recall: 1.0
    precision: 0.0287224948406
    f1_score: 0.0558410957456
  }
  confidence_metrics_entry {
    confidence_threshold: 0.0299999993294
    recall: 1.0
    precision: 0.0430837422609
    f1_score: 0.0826084092259
  }
}
create_time {
  seconds: 1526971489
  nanos: 218070000
}

我想解析输入并以csv格式保存为name,annotation_spec_id,classitication_metrics(au_prc,base_au_prc)confidence_metrics_entry(recall,precision,f1)

我已尝试使用json_loadsjson_dumps,但由于无法解码JSON对象,因此会引发不同的错误。因为这个输入无效json。

如何加载和解析文件?我应该以哪种格式保存输入文件?

提前感谢。

0 个答案:

没有答案