Ejemplo n.º 1
0
def evaluate_incomplete_entry(classifier_cls):
    '''
  TODO: Fill out the function to compute marginal probabilities.

  Params:
   - classifier_cls: either NBClassifier or TANBClassifier
   - train_subset: train the classifier on a smaller subset of the training
    data
  Returns:
   - P_c_pred: P(C = 1 | A_observed) as a scalar.
   - PA_12_eq_1: P(A_12 = 1 | A_observed) as a scalar.

  '''
    global A_base, C_base

    # train a TANB classifier on the full dataset
    classifier = classifier_cls(A_base, C_base)

    # load incomplete entry 1
    entry = load_incomplete_entry()

    c_pred, logP_c_pred = classifier.classify(entry)
    P_c_pred = np.exp(logP_c_pred)
    print('  P(C={}|A_observed) = {:2.4f}'.format(c_pred, P_c_pred))

    # TODO: write code to compute this!
    a_pred, logP_a_pred = classifier.unobserved_probability(entry, index=11)
    PA_12_eq_1 = np.exp(logP_a_pred)
    print('  P(A={}|A_observed) = {:2.4f}'.format(12, PA_12_eq_1))

    # PA_12_eq_1 = None

    return P_c_pred, PA_12_eq_1
Ejemplo n.º 2
0
def predict_unobserved(classifier_cls, index=11):
    global A_base, C_base

    # train a classifier on the full dataset
    classifier = classifier_cls(A_base, C_base)

    # load incomplete entry 1
    entry = load_incomplete_entry()

    a_pred = classifier.predict_unobserved(entry, index)
    print("  P(A{}=1|A_observed) = {:2.4f}".format(index + 1, a_pred[1]))

    return
Ejemplo n.º 3
0
def evaluate_incomplete_entry(classifier_cls):

    global A_base, C_base

    # train a classifier on the full dataset
    classifier = classifier_cls(A_base, C_base)

    # load incomplete entry 1
    entry = load_incomplete_entry()

    c_pred, logP_c_pred = classifier.classify(entry)
    print("  P(C={}|A_observed) = {:2.4f}".format(c_pred, np.exp(logP_c_pred)))

    return
Ejemplo n.º 4
0
def evaluate_missing_posterior(classifier_cls, missing_idx):
    global A_base, C_base

    # train a TANB classifier on the full dataset
    classifier = classifier_cls(A_base, C_base)

    # load incomplete entry 1
    entry = load_incomplete_entry()

    m_pred, logP_m_pred = classifier.missing_posterior(entry, missing_idx)

    print('  P(M={}|A_observed) = {:2.4f}'.format(m_pred, np.exp(logP_m_pred)))

    return
Ejemplo n.º 5
0
def evaluate_incomplete_entry(classifier_cls):

  global A_base, C_base

  # train a TANB classifier on the full dataset
  classifier = classifier_cls(A_base, C_base)

  # load incomplete entry 1
  entry = load_incomplete_entry()

  c_pred, logP_c_pred = classifier.classify(entry)

  print '  P(C={}|A_observed) = {:2.4f}'.format(c_pred, np.exp(logP_c_pred))

  return
Ejemplo n.º 6
0
def evaluate_incomplete_entry(classifier_cls):

  global A_base, C_base

  # train a TANB classifier on the full dataset
  classifier = classifier_cls(A_base, C_base)

  # load incomplete entry 1
  entry = load_incomplete_entry()




  prob = classifier.shuffle(entry)

  print '  P(C={}|A_observed) = {:2.7f}'.format(1, prob)

  return