def get_item_labels(item):
     if add_parents:
         all_labels = set(item['labels'])
         for label in item['labels']:
             for l2 in disease_label_table.get_inferred_labels(label):
                 all_labels.add(l2)
         return list(all_labels)
     else:
         return item['labels']
def best_guess(classifier, X):
    probs = classifier.predict_proba(X)[0]
    p_max = max(probs)
    result = {}
    for i,p in enumerate(probs):
        cutoff_ratio = 0.65
        parents = disease_label_table.get_inferred_labels(classifier.classes_[i])
        if p >= p_max * cutoff_ratio:
            result[i] = max(p, result.get(i, 0))
            for i2, label in enumerate(classifier.classes_):
                if label in parents:
                    result[i2] = max(p, probs[i2], result.get(i2, 0))
    return result.items()
 def test_inference(self):
     import disease_label_table
     self.assertSetEqual(set(['Avian Influenza', 'Influenza']),
         set(disease_label_table.get_inferred_labels('Avian Influenza H7N9')))