Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get output of sklearn.metrics.classification_report as a dict?

I have been trying to get the classification report in the form of a dictionary. So according to the scikit-learn 0.20 documentation, I do:

from sklearn import metrics

rep = metrics.classification_report(y_true, y_pred, output_dict=True)

But get an error saying

TypeError: classification_report() got an unexpected keyword argument 'output_dict'
The scikit-learn module in my machine was initially 0.19.1 but even after updating it to 0.20, the same error message shows.
like image 815
Bidisha Das Avatar asked Oct 10 '18 12:10

Bidisha Das


People also ask

What does Classification_report return?

A classification report is a performance evaluation metric in machine learning. It is used to show the precision, recall, F1 Score, and support of your trained classification model.

What is the Classification_report () under the Sklearn metrics package used for?

A Classification report is used to measure the quality of predictions from a classification algorithm. How many predictions are True and how many are False. More specifically, True Positives, False Positives, True negatives and False Negatives are used to predict the metrics of a classification report as shown below.

What is support in metrics Classification_report?

support. Support is the number of actual occurrences of the class in the specified dataset. Imbalanced support in the training data may indicate structural weaknesses in the reported scores of the classifier and could indicate the need for stratified sampling or rebalancing.


1 Answers

This error should not show up as long as you have scikit-learn 0.20.0 installed. If you are trying this in a jupyter notebook, make sure the correct version reflects in your notebook using:

import sklearn
print(sklearn.__version__)

If you've upgraded scikit-learn but jupyter shows the wrong version of the package, make sure jupyter is installed in your current environment (and restart jupyter in a new terminal).

like image 106
spundian Avatar answered Oct 25 '22 05:10

spundian