簡體   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