始める無料で始める

混同行列(Confusion matrix)

混同行列は、モデルの精度を確認し始めるのに非常に有用です。sensitivity(感度)、specificity(特異度)、F1-score を含む幅広い指標を計算するために必要な値が得られます。

あなたは X線画像に基づいて腕の骨折有無を予測する分類モデルを作成しました。テストデータに対して、次の混同行列が得られています。

Prediction: 0 Prediction: 1
Actual: 0 324 (TN) 15 (FP)
Actual: 1 123 (FN) 491 (TP)

この演習はコースの一部です

Python によるモデル検証

コースを見る

演習の手順

  • 混同行列を使って全体の Accuracy(正解率)を計算してください。
  • 混同行列を使って Precision(適合率)と Recall(再現率)を計算してください。
  • 3つの print 文を使って、それぞれの指標を出力してください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Calculate and print the accuracy
accuracy = (____ + ____) / (953)
print("The overall accuracy is {0: 0.2f}".format(accuracy))

# Calculate and print the precision
precision = (____) / (____ + ____)
print("The precision is {0: 0.2f}".format(precision))

# Calculate and print the recall
recall = (____) / (____ + ____)
print("The recall is {0: 0.2f}".format(recall))
コードを編集して実行