本文整理汇总了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)
#.........这里部分代码省略.........