def count_predictions(label): """ count all predictions or all predictions associated to a specific label made. :param label: :return: total amount of classifications """ sess = Database().session() if label: rows = sess.query( func.count('*').filter(DBResult.label == "{label}".format( label=label))).scalar() else: rows = sess.query(func.count(DBResult.result_id)).scalar() sess.close() return rows
def calc_accuracies(): """ Calculates the accuracy with which the class was predicted. :param label: the class with which the associated precisions of the classifications are calculated :return: accuracy of associated predictions """ accuracies = {} sess = Database().session() for label in sess.query(DBResult.label): label = list(label)[0] acc_sum = sess.query(func.sum(DBResult.accuracy)).filter( DBResult.label == "{label}".format(label=label)).scalar() accuracies.update({ label: round(acc_sum / DBClassification.count_predictions(label), 2) }) sess.close() return accuracies
def total_predictions(): """ counts the number of predictions of the corresponding classes :return: The amount of predictions belong to each corresponding class """ predictions = {} sess = Database().session() amounts = [] for label in sess.query(DBResult.label): amounts.append(label) sess.close() predictions.update({ list(label)[0]: amount for label, amount in Counter(amounts).items() }) total_amount = reduce(lambda x, y: x + y, Counter(amounts).values()) return predictions, total_amount
def resolve_answers(self, *args, **kwargs): return Database.query(AnswerModel).all()
def resolve_answer(self, *args, **kwargs): return Database.query(AnswerModel).first()