Accuracy is the share of predictions that match their actual class labels. For binary classification, accuracy = (true positives + true negatives) / total predictions; multiply by 100 to express it as a percentage. Each observation must have a prediction. section 5.2.4
Table 5.1 Confusion matrix for raisin classification. A confusion matrix stores classification metrics from a regression with actual and predicted binary outcomes.
|
Predicted
|
|||
|---|---|---|---|
|
Kecimen (0)
|
Besni (1)
|
||
|
Actual
|
Kecimen (0)
|
tn
|
fp
|
|
Besni (1)
|
fn
|
tp
|
|
The confusion matrix places correct predictions on the true-positive and true-negative cells. Its other cells count false positives and false negatives. section 5.2.4
Raisin classification
A logistic regression correctly identifies 397 observations of class 0 and 384 of class 1. With 900 observations, accuracy is (397 + 384) / 900 × 100 = 86.78%. The remaining 119 predictions give a misclassification rate of 13.22%. section 5.2.4
For a test set, pass actual and predicted labels to `metrics.accuracy_score(y_test, y_pred)`. Multiply its result by 100 for a percentage. A decision tree predicts 61% of fourth-down conversion outcomes correctly; a random forest reaches 62% on the same test data. The small difference is useful for comparison, but accuracy alone does not show which class each model handles better. section 6.3.4 section 6.4.3
>>> from sklearn.metrics import confusion_matrix, >>> conf_matrix = confusion_matrix(y_test, y_pred) >>> print(conf_matrix) [[71 67] [36 91]]
The decision tree’s confusion matrix shows 71 correct class-0 predictions and 91 correct class-1 predictions, alongside 67 false positives and 36 false negatives. Inspecting these counts reveals errors hidden by the overall 61% accuracy. section 6.3.4
Judge whether an accuracy rate is useful in light of the errors it conceals. Missing a serious medical diagnosis and incorrectly flagging a healthy person have different consequences; sensitivity, specificity, and the confusion matrix help distinguish such mistakes. ROC AUC offers a separate assessment of discrimination and need not match accuracy. section 5.2.4































