예제 #1
0
 def include(self, patient):
   util_5353.assert_dict_key(patient, 'id', 'pt_filter')
   util_5353.assert_dict_key(patient, 'name', 'pt_filter')
   util_5353.assert_dict_key(patient, 'address', 'pt_filter')
   util_5353.assert_dict_key(patient, 'birthDate', 'pt_filter')
   util_5353.assert_dict_key(patient, 'gender', 'pt_filter')
   return True
예제 #2
0
        print('::: Problem 6 :::')
        six_ret = svm(dataset_id, train, test)
        util_5353.assert_list(six_ret, len(test), '6')

        print('::: Problem 7 :::')
        seven_ret_dt = evaluate(dataset_id, test_out, three_ret)
        seven_ret_kn = evaluate(dataset_id, test_out, four_ret)
        seven_ret_nb = evaluate(dataset_id, test_out, five_ret)
        seven_ret_sv = evaluate(dataset_id, test_out, six_ret)

        for seven_ret in [
                seven_ret_dt, seven_ret_kn, seven_ret_nb, seven_ret_sv
        ]:
            util_5353.assert_dict(seven_ret, '7')
            util_5353.assert_dict_key(seven_ret, 'accuracy', '7')
            util_5353.assert_float(seven_ret['accuracy'], '7')
            util_5353.assert_float_range((0.0, 1.0), seven_ret['accuracy'],
                                         '7')
            for target in targets[dataset_id]:
                util_5353.assert_dict_key(seven_ret, target, '7')
                util_5353.assert_dict(seven_ret[target], '7')
                util_5353.assert_dict_key(seven_ret[target], 'precision', '7')
                util_5353.assert_dict_key(seven_ret[target], 'recall', '7')
                util_5353.assert_dict_key(seven_ret[target], 'f1', '7')
                util_5353.assert_float(seven_ret[target]['precision'], '7')
                util_5353.assert_float(seven_ret[target]['recall'], '7')
                util_5353.assert_float(seven_ret[target]['f1'], '7')
                util_5353.assert_float_range(
                    (0.0, 1.0), seven_ret[target]['precision'], '7')
                util_5353.assert_float_range((0.0, 1.0),
예제 #3
0
  GOLD = ['Adult', 'Aged', 'Chemoradiotherapy', 'Diffusion Magnetic Resonance Imaging', 'Female', 'Humans', 'Medical Oncology', 'Middle Aged', 'Reproducibility of Results', 'Time Factors', 'Treatment Outcome', 'Tumor Burden', 'Uterine Cervical Neoplasms']
  util_5353.assert_list(three_ret, len(GOLD), '3', valid_values=GOLD)

  print('::: Problem 4 :::')
  mesh_list = ['Humans', 'Female', 'Male', 'Animals', 'Treatment Outcome',
               'Neoplasms', 'Prognosis', 'Risk Factors', 'Breast Neoplasms', 'Lung Neoplasms']
  mesh_set = set()
  for pmid in pmids:
    mesh_set.update(mesh(data, pmid))
  for m in mesh_list:
    if m not in mesh_set:
      util_5353.die('4', 'Assertions assume MeSH term is present: %s', m)
  four_ret = svm_predict_unigram(data, train, test, mesh_list)
  util_5353.assert_dict(four_ret, '4')
  for m in mesh_list:
    util_5353.assert_dict_key(four_ret, m, '4')
    util_5353.assert_list(four_ret[m], None, '4', valid_values=pmids)
    util_5353.assert_int_range((0, len(test)), len(four_ret[m]), '4')
  util_5353.assert_int_range((len(test)/2, len(test)), len(four_ret['Humans']), '4')

  print('::: Problem 5 :::')
  five_ret = svm_predict_tfidf(data, train, test, mesh_list)
  util_5353.assert_dict(five_ret, '5')
  for m in mesh_list:
    util_5353.assert_dict_key(five_ret, m, '5')
    util_5353.assert_list(five_ret[m], None, '5', valid_values=pmids)
    util_5353.assert_int_range((0, len(test)), len(five_ret[m]), '5')
  util_5353.assert_int_range((len(test)/2, len(test)), len(five_ret['Humans']), '5')

  print('::: Problem 6 :::')
  K = 10
예제 #4
0
if __name__ == '__main__':

  # Include all patients
  pt_filter = all_pass_filter()

  print('::: Problem 1 :::')
  one_ret = num_patients(pt_filter)
  util_5353.assert_tuple(one_ret, 2, '1')
  util_5353.assert_int_range((0, 10000000), one_ret[0], '1')
  util_5353.assert_int_range((0, 10000000), one_ret[1], '1')

  print('::: Problem 2 :::')
  two_ret = patient_stats(pt_filter)
  util_5353.assert_dict(two_ret, '2')
  for key in ['gender', 'marital_status', 'race', 'ethnicity', 'age', 'with_address']:
    util_5353.assert_dict_key(two_ret, key, '2')
    util_5353.assert_dict(two_ret[key], '2')
    for key2 in two_ret[key].keys():
      util_5353.assert_str(key2, '2')
    util_5353.assert_prob_dict(two_ret[key], '2')
  for key2 in two_ret['age'].keys():
    if not key2.isdigit():
      util_5353.die('2', 'age key should be year: %s', key2)

  print('::: Problem 3 :::')
  three_ret = diabetes_quality_measure(pt_filter)
  util_5353.assert_tuple(three_ret, 3, '3')
  util_5353.assert_int_range((0, 1000000), three_ret[0], '3')
  util_5353.assert_int_range((0, 1000000), three_ret[1], '3')
  util_5353.assert_int_range((0, 1000000), three_ret[2], '3')
  if three_ret[0] < three_ret[1] or three_ret[1] < three_ret[2]:
# encouraged to look at this code, however, especially if your code crashes.
if __name__ == '__main__':

  # Include all patients
  pt_filter = all_pass_filter()

  print('::: Problem 1 :::')
  one_ret = num_patients(pt_filter)
  util_5353.assert_tuple(one_ret, 2, '1')
  util_5353.assert_int_range((0, 10000000), one_ret[0], '1')
  util_5353.assert_int_range((0, 10000000), one_ret[1], '1')

  print('::: Problem 2 :::')
  two_ret = patient_stats(pt_filter)
  util_5353.assert_dict(two_ret, '2')
  util_5353.assert_dict_key(two_ret, 'gender', '2')
  util_5353.assert_dict_key(two_ret, 'marital_status', '2')
  util_5353.assert_dict_key(two_ret, 'race', '2')
  util_5353.assert_dict_key(two_ret, 'ethnicity', '2')
  util_5353.assert_dict_key(two_ret, 'age', '2')
  util_5353.assert_dict_key(two_ret, 'with_address', '2')
  util_5353.assert_dict(two_ret['gender'], '2')
  util_5353.assert_dict(two_ret['marital_status'], '2')
  util_5353.assert_dict(two_ret['race'], '2')
  util_5353.assert_dict(two_ret['ethnicity'], '2')
  util_5353.assert_dict(two_ret['age'], '2')
  util_5353.assert_dict(two_ret['with_address'], '2')
  util_5353.assert_prob_dict(two_ret['gender'], '2')
  util_5353.assert_prob_dict(two_ret['marital_status'], '2')
  util_5353.assert_prob_dict(two_ret['race'], '2')
  util_5353.assert_prob_dict(two_ret['ethnicity'], '2')