文本分类:多标签分类与NLTK-Trainer的使用
多标签分类
在文本分类中,除了常见的二分类器,有时我们还需要处理多标签分类的情况。多标签分类器可以为一个样本分配多个标签。下面将介绍如何使用多个二分类器来构建一个多标签分类器。
准备工作
使用路透社语料库(reuters corpus)进行训练和评估,该语料库包含多标签文本。
from nltk.corpus import reuters
print(len(reuters.categories())) # 输出:90
我们将为每个标签训练一个二分类器,最终会得到90个二分类器。
具体步骤
- 计算高信息词 :使用
featx.py中的reuters_high_info_words()函数计算路透社语料库中的高信息词。
from nltk.corpus import reuters
from nltk.collocations import BigramAssocMeasures
def reuters_high_info_words(score_fn=BigramAssocMeasures.chi_sq):
labeled_words = []
for label in reuters.categories():
la
超级会员免费看
订阅专栏 解锁全文
463

被折叠的 条评论
为什么被折叠?



