本文整理匯總了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)
#.........這裏部分代碼省略.........