当前位置: 首页>>代码示例>>Python>>正文


Python Dataset.test方法代码示例

本文整理汇总了Python中Dataset.Dataset.test方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.test方法的具体用法?Python Dataset.test怎么用?Python Dataset.test使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dataset.Dataset的用法示例。


在下文中一共展示了Dataset.test方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: runner

# 需要导入模块: from Dataset import Dataset [as 别名]
# 或者: from Dataset.Dataset import test [as 别名]
def runner(
        PATH_DATA,
        RATIO_TEST_DATA,
        RATIO_SPECIFICITY,
        RATIO_CONFIDENCE,
        EXPERIMENTS,
        fe,
        setting_name
    ):

    results = []
    errors = Counter()
    qtypes = QuestionTypes()
    for e in range(1, EXPERIMENTS + 1):

        start = time.time()
        dataset = Dataset(PATH_DATA)
        dataset.load()

        invprob = InverseProbabilities(dataset)
        index = Index(invprob)

        train = [
    #         (bow(fe, label, RATIO_SPECIFICITY, prob_filter=invprob) + bow(fe, text, prob_filter=invprob), label, mark)
            (bow(fe, text, RATIO_SPECIFICITY, prob_filter=invprob), label, mark)
            for text, label, mark in dataset.train()
        ]
        train = train * 4

        test = [
            (bow(fe, label, RATIO_SPECIFICITY, prob_filter=invprob), label, mark)
#             (bow(fe, text, RATIO_SPECIFICITY, prob_filter=invprob), label, mark)
            for text, label, mark in dataset.test()
            if mark
        ][:int(len(train) * RATIO_TEST_DATA)]

        test += [
            (bow(fe, label, RATIO_SPECIFICITY, prob_filter=invprob), label, mark)
#             (bow(fe, text, RATIO_SPECIFICITY, prob_filter=invprob), label, mark)
            for text, label, mark in dataset.test()
            if not mark
        ][:len(test)]

        for tbow, label, mark in train:
            index.update(tbow)
            index.add(label)

        tp, tn, fp, fn, prec, rec, f, duration = 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0
        marked = sum([1 for _, _, mark in test if mark])
        for tbow, label, mark in test:
            qtypes.increment(label)
            expectation = sum([
                invprob[w]
                for w in set(bow(fe, label, RATIO_SPECIFICITY, prob_filter=invprob))
            ])
            matches = index(tbow)

            if not matches and not mark:
                tn += 1
                continue
            elif not matches and mark:
                fn += 1
                errors[('fn', '', label)] += 1
                qtypes.update('fn', None, label)
                continue

            best_match = matches[0]
            guess = best_match[2]
            sim = best_match[0]
            ratio = sim / (expectation + 0.1)

            if ratio <= RATIO_CONFIDENCE:
                if not mark:
                    tn += 1
                    continue
                else:
                    fn += 1
                    errors[('fn', '', label)] += 1
                    qtypes.update('fn', None, label)
                    continue
            else:
                if mark and guess == label:
                    tp += 1
                else:
                    fp += 1
                    _qtype = '_'.join(guess.lower().split()[:2])
                    errors[('fp', guess, label)] += 1
                    qtypes.update('fp', guess, label)

            duration = time.time() - start
            if tp:
                prec = tp / float(tp + fp)
                rec = tp / float(tp + fn)
                f = f1(prec, rec)
            else:
                prec, rec, f = 0.0, 0.0, 0.0

        vector = (e, _r(tp), _r(tn), _r(fp), _r(fn),
                  _r(prec), _r(rec), _r(f), _r(duration))
        results.append(vector)
#.........这里部分代码省略.........
开发者ID:JordiCarreraVentura,项目名称:question_answer,代码行数:103,代码来源:SecondTask.py


注:本文中的Dataset.Dataset.test方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。