首页 > 解决方案 > 如何计算给定json的准确性

问题描述

我有一个包含多个键的 JSON 文件,每个键都有一个包含两个列表
的值第一个列表是我的模型预测
第二个列表是真实值


{
  "PMUL1635.json_0": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel"
    ],
    [
      "hotel-area-east",
      "hotel-stars-4"
    ]
  ],
  "PMUL1635.json_1": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare"
    ],
    [
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes"
    ]
  ],
  "PMUL1635.json_2": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-warkworth house"
    ],
    [
      "hotel-name-wartworth",
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes"
    ]
  ],
  "PMUL1635.json_3": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-warkworth house",
      "hotel-book day-friday"
    ],
    [
      "hotel-book day-friday",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-wartworth",
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes"
    ]
  ],
  "PMUL1635.json_4": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-warkworth house",
      "hotel-book day-friday",
      "train-day-friday",
      "train-departure-cambridge",
      "train-destination-bishops stortford"
    ],
    [
      "hotel-book day-friday",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-wartworth",
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes",
      "train-destination-bishops stortford",
      "train-day-friday",
      "train-departure-cambridge"
    ]
  ],
  "PMUL1635.json_5": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-warkworth house",
      "hotel-book day-friday",
      "train-day-friday",
      "train-departure-cambridge",
      "train-destination-bishops stortford",
      "train-arriveby-19:45"
    ],
    [
      "hotel-book day-friday",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-wartworth",
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes",
      "train-destination-bishops stortford",
      "train-day-friday",
      "train-arriveby-19:45",
      "train-departure-cambridge"
    ]
  ],
  "PMUL1635.json_6": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-warkworth house",
      "hotel-book day-friday",
      "train-day-friday",
      "train-departure-cambridge",
      "train-destination-bishops stortford",
      "train-arriveby-19:45"
    ],
    [
      "hotel-book day-friday",
      "hotel-book people-1",
      "hotel-book stay-1",
      "hotel-name-wartworth",
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes",
      "train-book people-1",
      "train-destination-bishops stortford",
      "train-day-friday",
      "train-arriveby-19:45",
      "train-departure-cambridge"
    ]
  ],
  "PMUL1635.json_7": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare",
      "hotel-book people-3",
      "hotel-book stay-4",
      "hotel-name-warkworth house",
      "hotel-book day-friday",
      "train-day-friday",
      "train-departure-cambridge",
      "train-destination-bishops stortford",
      "train-arriveby-19:45"
    ],
    [
      "hotel-book day-monday",
      "hotel-book people-3",
      "hotel-book stay-4",
      "hotel-name-wartworth",
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes",
      "train-book people-1",
      "train-destination-bishops stortford",
      "train-day-friday",
      "train-arriveby-19:45",
      "train-departure-cambridge"
    ]
  ],
  "PMUL1635.json_8": [
    [
      "hotel-area-east",
      "hotel-stars-4",
      "hotel-type-hotel",
      "hotel-internet-yes",
      "hotel-parking-yes",
      "hotel-pricerange-dontcare",
      "hotel-book people-3",
      "hotel-book stay-4",
      "hotel-name-warkworth house",
      "hotel-book day-friday",
      "train-day-friday",
      "train-departure-cambridge",
      "train-destination-bishops stortford",
      "train-arriveby-19:45"
    ],
    [
      "hotel-book day-monday",
      "hotel-book people-3",
      "hotel-book stay-4",
      "hotel-name-wartworth",
      "hotel-area-east",
      "hotel-parking-yes",
      "hotel-stars-4",
      "hotel-internet-yes",
      "train-book people-1",
      "train-destination-bishops stortford",
      "train-day-friday",
      "train-arriveby-19:45",
      "train-departure-cambridge"
    ]
  ],
  "PMUL1181.json_0": [
    [
      "train-destination-cambridge"
    ],
    [
      "train-destination-cambridge"
    ]
  ],
  "PMUL1181.json_1": [
    [
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich",
      "train-leaveat-18:45"
    ],
    [
      "train-leaveat-18:45",
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich"
    ]
  ],
  "PMUL1181.json_2": [
    [
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich",
      "train-leaveat-18:45"
    ],
    [
      "train-leaveat-18:45",
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich"
    ]
  ],
  "PMUL1181.json_3": [
    [
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich",
      "train-leaveat-18:45",
      "train-book people-1"
    ],
    [
      "train-book people-1",
      "train-leaveat-18:45",
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich"
    ]
  ],
  "PMUL1181.json_4": [
    [
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich",
      "train-leaveat-18:45",
      "train-book people-1",
      "attraction-area-east",
      "attraction-type-multi hall"
    ],
    [
      "attraction-type-multiple sports",
      "attraction-area-east",
      "train-book people-1",
      "train-leaveat-18:45",
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich"
    ]
  ],
  "PMUL1181.json_5": [
    [
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich",
      "train-leaveat-18:45",
      "train-book people-1",
      "attraction-area-east",
      "attraction-type-multi hall",
      "attraction-name-cherry hinton village centre"
    ],
    [
      "attraction-type-multiple sports",
      "attraction-name-cherry hinton village centre",
      "attraction-area-east",
      "train-book people-1",
      "train-leaveat-18:45",
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich"
    ]
  ],
  "PMUL1181.json_6": [
    [
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich",
      "train-leaveat-18:45",
      "train-book people-1",
      "attraction-area-east",
      "attraction-type-multi hall",
      "attraction-name-cherry hinton village centre"
    ],
    [
      "attraction-type-multiple sports",
      "attraction-name-cherry hinton village centre",
      "attraction-area-east",
      "train-book people-1",
      "train-leaveat-18:45",
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich"
    ]
  ],
  "PMUL1181.json_7": [
    [
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich",
      "train-leaveat-18:45",
      "train-book people-1",
      "attraction-area-east",
      "attraction-type-multi hall",
      "attraction-name-cherry hinton village centre"
    ],
    [
      "attraction-type-multiple sports",
      "attraction-name-cherry hinton village centre",
      "attraction-area-east",
      "train-book people-1",
      "train-leaveat-18:45",
      "train-destination-cambridge",
      "train-day-wednesday",
      "train-departure-norwich"
    ]
  ],
  "PMUL0287.json_0": [
    [
      "restaurant-name-riverside brasserie"
    ],
    [
      "restaurant-name-riverside brasserie"
    ]
  ],
  "PMUL0287.json_1": [
    [
      "restaurant-name-riverside brasserie",
      "restaurant-book day-sunday",
      "restaurant-book people-6",
      "restaurant-book time-14:30"
    ],
    [
      "restaurant-book day-sunday",
      "restaurant-book people-6",
      "restaurant-book time-14:30",
      "restaurant-food-modern european",
      "restaurant-pricerange-moderate",
      "restaurant-name-riverside brasserie",
      "restaurant-area-centre"
    ]
  ],
  "PMUL0287.json_2": [
    [
      "restaurant-name-riverside brasserie",
      "restaurant-book day-sunday",
      "restaurant-book people-6",
      "restaurant-book time-14:30",
      "hotel-area-south"
    ],
    [
      "restaurant-book day-sunday",
      "restaurant-book people-6",
      "restaurant-book time-14:30",
      "restaurant-food-modern european",
      "restaurant-pricerange-moderate",
      "restaurant-name-riverside brasserie",
      "restaurant-area-centre",
      "hotel-area-south"
    ]
  ],
  "PMUL0287.json_3": [
    [
      "restaurant-name-riverside brasserie",
      "restaurant-book day-sunday",
      "restaurant-book people-6",
      "restaurant-book time-14:30",
      "hotel-area-south",
      "hotel-pricerange-dontcare",
      "hotel-stars-4"
    ],
    [
      "restaurant-book day-sunday",
      "restaurant-book people-6",
      "restaurant-book time-14:30",
      "restaurant-food-modern european",
      "restaurant-pricerange-moderate",
      "restaurant-name-riverside brasserie",
      "restaurant-area-centre",
      "hotel-area-south",
      "hotel-stars-4"
    ]
  ]
}

像这样的事情:)
我想计算一两个一个键列表之间的精确精度并获得所有精度的平均值
我真的不知道如何真正做到这一点


import json

json_file = open("test.json", encoding="utf8")
data = json.load(json_file)

# Iterating through the json
# list
for item in data["conversation581.json_-1"]:
    print(item)
    if set(pred_state) == set(i.gold_state): #this do not work :) but i want sth like this
        joint_acc += 1
 # and then get the average accuarcy between all keys

为了准确,我需要这样的东西:

if i in test_json:
    final_count+=1
    if set(pred_state) == set(i.gold_state):
        final_joint_acc += 1
  
final_joint_acc_score = final_joint_acc / final_count

我没有任何想法来解决它......
有没有人可以帮忙?

标签: pythonjsonexact-matchacc

解决方案


推荐阅读