Extracting the performance report

We also have a function in scikit-learn that can directly print the precision, recall, and F1 scores for us. Let's see how to do this.

How to do it…

  1. Add the following lines to a new Python file:
    from sklearn.metrics import classification_report
    y_true = [1, 0, 0, 2, 1, 0, 3, 3, 3]
    y_pred = [1, 1, 0, 2, 1, 0, 1, 3, 3]
    target_names = ['Class-0', 'Class-1', 'Class-2', 'Class-3']
    print(classification_report(y_true, y_pred, target_names=target_names))
  2. If you run this code, you will see the following on your Terminal:
    How to do it…

    Instead of computing these metrics separately, you can directly use this function to extract those statistics ...

Get Python: Real World Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.