gpt4 book ai didi

python - scikit-learn 获得所选类别的分类器的分类/分数的确定性

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:29 25 4
gpt4 key购买 nike

我正在做一些多类文本分类,它很适合我的需要:

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 -> “什么都不会改变我对该新闻类别的看法”)。我应该如何获得确定性值/该类别的预测值得分?

最佳答案

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

Docs .

关于python - scikit-learn 获得所选类别的分类器的分类/分数的确定性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35793813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com