示例#1
0
"""

models = ['unweighted', 'weighted']
sequence_length = 3

# Reads in the data containing the predictions of a model under the given settings.
filename = 'analyses/old_model_sequence_length_3_test_set_predictions.csv'
data = Preprocessing(filename)
statistics = Statistics(data)

# Gets the precision, recall and f1-score for every dialogue act for different model input settings.
for weighted in models:
    accuracy_dict = dict()
    for dialogue_act in data.DAs:
        columns = ['labels_' + weighted, 'predictions_' + weighted]
        precision, recall, f1 = statistics.precision_recall_f1(
            data.data, columns, dialogue_act)

        if 'all_levels' not in accuracy_dict.keys():
            accuracy_dict['all_levels'] = dict()
            accuracy_dict['all_levels']['p'] = dict()
            accuracy_dict['all_levels']['r'] = dict()
            accuracy_dict['all_levels']['f1'] = dict()
        accuracy_dict['all_levels']['p'][dialogue_act] = precision
        accuracy_dict['all_levels']['r'][dialogue_act] = recall
        accuracy_dict['all_levels']['f1'][dialogue_act] = f1

        for level in data.levels:
            level_data = data.data[data.data['level'] == level]
            precision, recall, f1 = statistics.precision_recall_f1(
                level_data, columns, dialogue_act)
5       b           b
6       b           c
7       b           c
8       c           a
9       c           b
10      c           a
11      c           b
12      d           a
13      b           e


"""

statistics = Statistics(data)
for class_name in classes:
    precision, recall, f1 = statistics.precision_recall_f1(
        data, ['labels', 'predictions'], class_name)
    print(class_name + ' precision is: ' + str(round(precision, 4)))
    print(class_name + ' recall is: ' + str(round(recall, 4)))
    print(class_name + ' f1 is: ' + str(round(f1, 4)))
""" 
Desired output:

a precision = 2/6 = 0.33
a recall = 2/4 = 0.5
a f1 = 2 * (0.33 * 0.5) / 0.83 = 0.4

b precision = 1/4 = 0.25
b recall = 1/5 = 0.20
b f1 = 2 * (0.25 * 0.20) / 0.45 = 0.2222

c precision = 0/3 = 0