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

Cabu

I am doing some multiclass text classification and it work well for my needs:

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])

Now, what i would like to have with the predicted category is its 'certainty' from the predictor (eg: 0.0 -> "I have rolled a dice to choose a category" up to 1.0 -> "Nothing will make change my mind about the category of that news"). How should I get that certainty value / the score of the predictor for that category?

solomkinmv

If you need something like probability of the category, you have to use predict_proba() method of the classifier.

Docs.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Difference between classification and regression score in Python scikit learn

From Dev

Scikit-learn returning incorrect classification report and accuracy score

From Dev

How to get all alpha values of scikit-learn SVM classifier?

From Dev

Scikit learn-Classification

From Dev

How can I perform ensemble (multi-classifier) classification using scikit-learn?

From Dev

How to tell scikit-learn for which label the F-1/precision/recall score is given (in binary classification)?

From Dev

scikit-learn classification report - Precision and F-score are ill-defined and being set to 0.0

From Dev

Scikit-learn get propability of a sample belonging to a category

From Dev

multilabel classification for text with scikit learn

From Dev

Evaluating convergence of SGD classifier in scikit learn

From Dev

Evaluating convergence of SGD classifier in scikit learn

From Dev

How to get most informative features for scikit-learn classifier for different class?

From Dev

Scikit Learn multiclass classification (perfect results)

From Dev

ValueError : Random forest classification by scikit learn

From Dev

similarity measure scikit-learn document classification

From Dev

Get SVM classification score in multiclass classification with OpenCV

From Dev

Scikit Learn TfidfVectorizer : How to get top n terms with highest tf-idf score

From Dev

Getting a negative score on using LassoCV.score() in scikit-learn

From Dev

What is the theorical foundation for scikit-learn dummy classifier?

From Dev

Converting JPG images for input to scikit learn SVM classifier

From Dev

Scikit-learn Ridge classifier: extracting class probabilities

From Dev

Does scikit learn include a Naive Bayes classifier with continuous inputs?

From Dev

Post-process classifier output in scikit learn Pipeline

From Dev

combine two different classifier result in scikit-learn python

From Dev

Plot Confusion Matrix with scikit-learn without a Classifier

From Dev

How to upgrade the classifier to the latest version of scikit-learn

From Dev

Converting JPG images for input to scikit learn SVM classifier

From Dev

Scikit-learn Ridge classifier: extracting class probabilities

From Dev

Understanding accuracy_score with scikit-learn with my own corpus?

Related Related

  1. 1

    Difference between classification and regression score in Python scikit learn

  2. 2

    Scikit-learn returning incorrect classification report and accuracy score

  3. 3

    How to get all alpha values of scikit-learn SVM classifier?

  4. 4

    Scikit learn-Classification

  5. 5

    How can I perform ensemble (multi-classifier) classification using scikit-learn?

  6. 6

    How to tell scikit-learn for which label the F-1/precision/recall score is given (in binary classification)?

  7. 7

    scikit-learn classification report - Precision and F-score are ill-defined and being set to 0.0

  8. 8

    Scikit-learn get propability of a sample belonging to a category

  9. 9

    multilabel classification for text with scikit learn

  10. 10

    Evaluating convergence of SGD classifier in scikit learn

  11. 11

    Evaluating convergence of SGD classifier in scikit learn

  12. 12

    How to get most informative features for scikit-learn classifier for different class?

  13. 13

    Scikit Learn multiclass classification (perfect results)

  14. 14

    ValueError : Random forest classification by scikit learn

  15. 15

    similarity measure scikit-learn document classification

  16. 16

    Get SVM classification score in multiclass classification with OpenCV

  17. 17

    Scikit Learn TfidfVectorizer : How to get top n terms with highest tf-idf score

  18. 18

    Getting a negative score on using LassoCV.score() in scikit-learn

  19. 19

    What is the theorical foundation for scikit-learn dummy classifier?

  20. 20

    Converting JPG images for input to scikit learn SVM classifier

  21. 21

    Scikit-learn Ridge classifier: extracting class probabilities

  22. 22

    Does scikit learn include a Naive Bayes classifier with continuous inputs?

  23. 23

    Post-process classifier output in scikit learn Pipeline

  24. 24

    combine two different classifier result in scikit-learn python

  25. 25

    Plot Confusion Matrix with scikit-learn without a Classifier

  26. 26

    How to upgrade the classifier to the latest version of scikit-learn

  27. 27

    Converting JPG images for input to scikit learn SVM classifier

  28. 28

    Scikit-learn Ridge classifier: extracting class probabilities

  29. 29

    Understanding accuracy_score with scikit-learn with my own corpus?

HotTag

Archive