示例#1
0
    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
示例#2
0
    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
示例#3
0
    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
示例#4
0
 def resolve_answers(self, *args, **kwargs):
     return Database.query(AnswerModel).all()
示例#5
0
 def resolve_answer(self, *args, **kwargs):
     return Database.query(AnswerModel).first()