所以我使用的是textblob库,但是性能很差。
我已经序列化它并在循环之前加载它(使用泡菜)。
目前只需0.1(用于小训练数据)和0.3 ( 33'000个测试数据)。我需要让它更快一点,这可能吗?
一些代码:
# Pass trainings before loop, so we can make performance a lot better
trained_text_classifiers = load_serialized_classifier_trainings(config["ALL_CLASSIFICATORS"])
# Specify witch classifiers are used by witch classes
filter_classifiers = get_classifiers_by_resource_names(trained_text_classifiers, config["FILTER_CLASSIFICATORS"])
signal_classifiers = get_classifiers_by_resource_names(trained_text_classifiers, config["SIGNAL_CLASSIFICATORS"])
for (url, headers, body) in iter_warc_records(warc_file, **warc_filters):
start_time = time.time()
body_text = strip_html(body);
# Check if url body passess filters, if yes, index, if no, ignore
if Filter.is_valid(body_text, filter_classifiers):
print "Indexing", url.url
resp = indexer.index_document(body, body_text, signal_classifiers, url=url, headers=headers, links=bool(args.save_linkgraph_domains))
else:
print "\n"
print "Filtered out", url.url
print "\n"
resp = 0这是一个循环,它对每个warc文件的正文和元数据执行检查。
这里有两个文本分类检查。
1)在过滤器(非常小的培训数据):
if trained_text_classifiers.classify(body_text) == "True":
return True
else:
return False2)在index_document中(33,000个培训数据):
prob_dist = trained_text_classifier.prob_classify(body)
prob_dist.max()
# Return the propability of spam
return round(prob_dist.prob("spam"), 2)分类和prob_classify是采用工具性能的方法。
发布于 2016-06-26 16:21:16
您可以对数据使用功能选择。一些较好的特征选择可以减少90%的特征,并保持分类性能。在特征选择中,您选择顶部特征(在Word模型的包中,您选择最重要的影响词),并根据这些单词(特征)进行训练模型。这减少了数据的维数(同时也防止了维度的诅咒),下面是一个很好的调查:特征选择综述
简单地说:
有两种特征选择方法:过滤和包装。
过滤方法几乎是以信息论为基础的。搜索“互信息”、"chi2“和.对于这种类型的特性选择
包装方法使用分类算法来估计库中最重要的特征。例如,您选择一些单词并评估分类性能(回忆、精确)。
另外,其他一些方法也是有用的。LSA和LSI可以超过分类性能和时间:分析。
您可以将镰刀用于特性选择和LSA:
selection.html
http://scikit-learn.org/stable/modules/decomposition.html
https://stackoverflow.com/questions/37969425
复制相似问题