Пример #1
0
    def test_d2_2_predict(self):
        global x_tr_pruned, x_dv_pruned, y_dv

        y_hat,scores = clf_base.predict(x_tr_pruned[0],hand_weights.theta_hand,labels)
        eq_(scores['pre-1980'],0.1)
        assert_almost_equals(scores['2000s'],1.3,places=5)
        eq_(y_hat,'2000s')
        eq_(scores['1980s'],0.0)

        y_hat = clf_base.predict_all(x_dv_pruned,hand_weights.theta_hand,labels)
        assert_almost_equals(evaluation.acc(y_hat,y_dv),.3422222, places=5)
Пример #2
0
def find_best_smoother(x_tr, y_tr, x_dv, y_dv, smoothers):
    """
    Find the smoothing value that gives the best accuracy on the dev data

    :param x_tr: training instances
    :param y_tr: training labels
    :param x_dv: dev instances
    :param y_dv: dev labels
    :param smoothers: list of smoothing values
    :returns: best smoothing value, scores
    :rtype: float, dict mapping smoothing value to score
    """

    smoothe_scores = dict()

    for s in smoothers:
        current_model = estimate_nb(x_tr, y_tr, s)
        y_hat = clf_base.predict_all(x_dv, current_model, list(set(y_tr)))
        smoothe_scores[s] = evaluation.acc(y_hat, y_dv)

    return (max(smoothe_scores, key=smoothe_scores.get), smoothe_scores)