how calculate accuracy in given json

283 views Asked by At

I have a JSON file containing multiple key, which each key has a value containing two list
the first list is my model prediction
the second list is the true value


{
  "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"
    ]
  ]
}

some thing like this:)
and I want to calculate the exact accuracy between set of two list of one key and get the average of all accuracies
I really do not know how to do that in true way


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

for accuracy I need some thing like this:

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

I haven't any idea to solve it...
Is there any body to help?

0

There are 0 answers