Exemplo n.º 1
0
	def evaluate_performance(self, class_labels, preds, gold, cl_perf = None, overall_perf = True, desc = " () ", print_perf = True):
		conf_matrix = confusion_matrix.ConfusionMatrix(class_labels, preds, gold, self.one_hot_encoding_preds, self.class_indices)
		if print_perf:
			if cl_perf is not None:
				for cl in cl_perf:
					p, r, f = conf_matrix.get_class_performance(cl)
					print(desc + " Class: " + cl + "\nP: " + str(p) + "\nR: " + str(r) + "\nF: " + str(f) + "\n")
			if overall_perf:
				print(desc + " Micro F1: " + str(conf_matrix.microf1) + "\nMacro F1: " + str(conf_matrix.macrof1) + "\n")
		return conf_matrix
Exemplo n.º 2
0
def eval_func(golds, preds, params=None):
    gold_labs = np.argmax(golds, axis=1)
    pred_labs = np.argmax(preds, axis=1)

    conf_matrix = confusion_matrix.ConfusionMatrix(params["dist_labels"],
                                                   pred_labs,
                                                   gold_labs,
                                                   False,
                                                   class_indices=True)
    res = conf_matrix.accuracy
    return 0 if math.isnan(res) else res
Exemplo n.º 3
0
def get_performance_seqlab(golds,
                           preds,
                           labels,
                           print=True,
                           print_per_class=True):
    golds_flat = []
    preds_flat = []
    for i in range(len(golds)):
        for j in range(len(golds[i])):
            if np.count_nonzero(golds[i][j]) > 0:
                golds_flat.append(golds[i][j])
                preds_flat.append(preds[i][j])
            else:
                break
    confmat = confusion_matrix.ConfusionMatrix(labels,
                                               preds_flat,
                                               golds_flat,
                                               one_hot_encoding=True)
    confmat.print_results()
    return confmat.accuracy