Chapter 15, Machine Learning: Classification, Regression and Clustering 11
a. Each estimator has a score method that returns an indication of how well the
estimator performs for the test data you pass as arguments.
b. For classification estimators, the score method returns the prediction accu-
racy for the test data.
c. You can perform hyperparameter tuning to try to determine the optimal value
for k.
d. All of the above statements are true.
15.3 Q2: Which of the following statements is false?
a. Another way to check a classification estimator’s accuracy is via a confusion
matrix, which shows only the incorrect predicted values (also known as the
misses) for a given class.
b. To create a confusion matrix imply call the function confusion_matrix from
the sklearn.metrics module, passing the expected classes and the pre-
dicted classes as arguments, as in:
from sklearn.metrics import confusion_matrix
confusion = confusion_matrix(y_true=expected, y_pred=predicted)
c. The y_true keyword argument in Part (b) specifies the test samples’ actual
classes.
d. The y_pred keyword argument in Part (b) specifies the predicted classes for
the test samples.
15.3 Q3: Consider the confusion matrix for the Digits dataset’s predictions:
array([[45, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 45, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 54, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 42, 0, 1, 0, 1, 0, 0],
[ 0, 0, 0, 0, 49, 0, 0, 1, 0, 0],
[ 0, 0, 0, 0, 0, 38, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 42, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 45, 0, 0],
[ 0, 1, 1, 2, 0, 0, 0, 0, 39, 1],
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 41]])
Which of the following statements is false?
a. The correct predictions are shown on the diagonal from top-left to bottom-
right—this is called the principal diagonal.