def classification_report(y_pred, y_true, labels):
"""
Parameters
----------
pass
Return
------
Classification report in form of string
"""
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
# ====== validate labels ====== #
labels = as_tuple(labels)
target_names = [str(i) for i in labels]
labels = list(range(0, len(labels)))
# ====== create report ====== #
s = ""
s += "Accuracy: %f\n" % accuracy_score(y_true, y_pred, normalize=True)
s += "Confusion matrix:\n"
s += str(confusion_matrix(y_true, y_pred, labels=labels)) + '\n'
s += "Report:\n"
s += str(classification_report(y_true, y_pred, labels=labels, digits=3,
target_names=target_names))
return s
评论列表
文章目录