Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am attending an online course where I am using some example and I am getting the wrong output as shown below:

import pandas as pd 

df = pd.read_csv(r'E:\Python Projects\Python-Data-Science-and-Machine-Learning-Bootcamp\Machine Learning\Árvores de decisão e Florestas Aleatórias\kyphosis.csv')

from sklearn.model_selection import train_test_split

x = df.drop('Kyphosis', axis=1)

y = df['Kyphosis']

X_train, X_test, y_train, y_test = train_test_split(x,y,test_size=0.33)

from sklearn.tree import DecisionTreeClassifier

dtree = DecisionTreeClassifier()

dtree.fit(X_train, y_train)

pred = dtree.predict(X_test)

from sklearn.metrics import classification_report

print(classification_report(y_test, pred))

My accuracy values are missing. Can anyone tell me why?

1 Answer

0 votes
by (36.8k points)

The text summary of classification report returns in this way only, nothing is missing

>>> from sklearn.metrics import classification_report

>>> y_true = [0, 1, 2, 2, 2]

>>> y_pred = [0, 0, 2, 2, 1]

>>> target_names = ['class 0', 'class 1', 'class 2']

>>> print(classification_report(y_true, y_pred, target_names=target_names))

              precision    recall  f1-score   support

<BLANKLINE>

     class 0       0.50      1.00      0.67         1

     class 1       0.00      0.00      0.00         1

     class 2       1.00      0.67      0.80         3

<BLANKLINE>

    accuracy                           0.60         5

   macro avg       0.50      0.56      0.49         5

weighted avg       0.70      0.60      0.61         5

<BLANKLINE>

>>> y_pred = [1, 1, 0]

>>> y_true = [1, 1, 1]

>>> print(classification_report(y_true, y_pred, labels=[1, 2, 3]))

              precision    recall  f1-score   support

<BLANKLINE>

           1       1.00      0.67      0.80         3

           2       0.00      0.00      0.00         0

           3       0.00      0.00      0.00         0

<BLANKLINE>

   micro avg       1.00      0.67      0.80         3

   macro avg       0.33      0.22      0.27         3

weighted avg       1.00      0.67      0.80         3

<BLANKLINE>

The macro avg include the reported average, weighted average and sample average

The micro avg indicated the multiple classes or multiple labels that are subset to classes. because they are corresponding to the accuracy.

So your accuracy is 74%

You can also refer to the link Data Science with python which provides the detail information of python from scratch and also real-time projects for learning, with a detail explanation of code.

Browse Categories

...