#python #json #exact-match #acc
#питон #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
У меня нет ни малейшей идеи, как это решить …
Есть ли какой-нибудь орган, который мог бы помочь?
Комментарии:
1. Можете ли вы указать ожидаемый результат (даже частично) в описании вопроса?
2. Как вы определяете «точность» только одного случая?
3. сначала спасибо за ваше внимание, например, если набор списков в PMUL1635.json_1 до PMUL1635.json_8 одинаковы ==> acc_PMUL1635.json = acc_PMUL1635.json 1 ………… и снова для набора списков в PMUL1181.json_1 и PMUL1181.json_2 , если они одинаковы ==> acc_PMUL1181.json = acc_PMUL1181.json 1………….. в конце концов, получите среднее значение точности….. (Обратите внимание, что * .json — это 2000, и у меня их здесь всего два!) вы понимаете, что я имею в виду? @Дэвид Росс
4. пожалуйста, прочтите приведенное выше объяснение @Kenny Ostrom
5. Я тоже не понимаю. Фактический «ожидаемый результат» поможет.