繁体   English   中英

scikit-learn确定所选类别的分类器的分类/分数

[英]scikit-learn get certainty of classification / score of the classifier for the chosen category

我正在做一些多类文本分类,它可以很好地满足我的需求:

classifier = Pipeline([
    ('vect', CountVectorizer(tokenizer=my_tokenizer, stop_words=stopWords, ngram_range=(1, 2), min_df=2)),
    ('tfidf', TfidfTransformer(norm='l2', use_idf=True, smooth_idf=True, sublinear_tf=False)),
    ('clf', MultinomialNB(alpha=0.01, fit_prior=True))])

categories = [list of my possible categories]

# Learning

news = [list of news already categorized]
news_cat = [the category of the corresponding news]

news_target_cat = numpy.searchsorted(categories, news_cat)

classifier = classifier.fit(news, news_target_cat)

# Categorizing

news = [list of news not yet categorized]

predicted = classifier.predict(news)

for i, pred_cat in enumerate(predicted):
    print(news[i])
    print(categories[pred_cat])

现在,我想有一个与预测类别是其从预测“确定性”(例如:0.0 - >“我已经推出一个骰子选择类别”高达1.0 - >“任何事情都不能使我改变主意约那个新闻的类别“)。 我应该如何获得该类别的确定性值/预测值得分?

如果您需要类别probability之类的东西,则必须使用分类器的predict_proba()方法。

文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM