Scikit-learn, get accuracy scores for each class

前端 未结 6 1207
说谎
说谎 2021-01-07 17:49

Is there a built-in way for getting accuracy scores for each class separatetly? I know in sklearn we can get overall accuracy by using metric.accuracy_score. Is

6条回答
  •  一向
    一向 (楼主)
    2021-01-07 18:15

    from sklearn.metrics import confusion_matrix
    y_true = [2, 0, 2, 2, 0, 1]
    y_pred = [0, 0, 2, 2, 0, 2]
    matrix = confusion_matrix(y_true, y_pred)
    matrix.diagonal()/matrix.sum(axis=1)
    

提交回复
热议问题