開始使用免費開始

混淆矩陣

混淆矩陣是檢視模型準確度的好起點。它提供計算多種評估指標所需的數值,包括敏感度、特異度,以及 F1 分數。

你已建立一個分類模型,根據 X 光影像來預測某人是否手臂骨折。在測試集上,你得到以下混淆矩陣:

預測:0 預測:1
實際:0 324(TN) 15(FP)
實際:1 123(FN) 491(TP)

本練習屬於課程

Python 的模型驗證

檢視課程

練習說明

  • 使用混淆矩陣計算整體準確率(accuracy)。
  • 使用混淆矩陣計算精確率(precision)與召回率(recall)。
  • 使用三個 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))
編輯並執行程式碼