
上QQ阅读APP看书,第一时间看更新
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…
- 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))
- If you run this code, you will see the following on your Terminal:
Instead of computing these metrics separately, you can directly use this function to extract those statistics from your model.