Course materials · Introduction to Machine Learning

Image Classification

English translation

Inspect misclassified samples behind image classification accuracy to examine the effects of preprocessing and data splitting.

Run import numpy as np and import matplotlib.pyplot as plt in a code cell before the practice code. Use np for array operations and plt for plots.

Before practice

01 Can equal Accuracy hide different error types?

Description

Errors may concentrate in particular classes or image conditions, so inspect actual misclassified samples.

02 Will the prediction for the same image remain unchanged under small noise?

Description

It depends on the noise level and error types. Keep the original Labels to compare Accuracy and errors.

Practice

Preview practice notebookDownload practice notebook

1. Image Arrays and Labels

Starting conditions

Use Classes 0–4 from the 8×8 images in sklearn load_digits, which requires no external download. Use a stratified 70/30 split with seed=7.

Procedure

  1. Inspect one image's 8×8 array and its Flattened 64 features.
  2. Perform baseline classification using StandardScaler fitted on train data and LogisticRegression(max_iter=1000).

Results to retain

Items to record and points to check
Step
Number of samples
Input shape
Label range

Points to check

  • Did you check image position information and the element order after Flatten?

2. Misclassifications and Ambiguous Inputs

Starting conditions

Select up to 6 misclassified Test samples and display each image, true label, prediction, and maximum probability together. If there are none, select low-confidence samples.

Procedure

  1. Find Indices where Test predictions differ from true labels and select the first 6 at most. If there are no misclassifications, select up to 6 in ascending order of maximum predicted probability.
  2. Plot the original 64 values for each Index as a 8×88\times8 image, with Test Index, true label, prediction, and maximum probability in the title.
  3. Distinguish features observed in the plots from model predictions in your explanation. Do not retrain the model or Scaler.

Results to retain

Items to record and points to check
Selected Test Index
Original image
True labels and predictions
Maximum prediction probability and observations

Points to check

  • Do the image, Label, and probabilities correspond to the selected Index?

3. Checking Other Inputs

Starting conditions

Add small noise using seed=7 to one selected test image, clip to the 0~16 range, and compare predictions.

Procedure

  1. Choose one test image from Activity 2 and record its index. Add small noise with Seed 7 and limit the pixel range using np.clip(...,0,16). For example, you can use normal noise with mean 0 and standard deviation 0.5.
  2. Display original and noisy images using the same brightness range. Feed each image into the same Scaler and model to obtain the predicted Class and per-Class probabilities.
  3. Record the noise distribution and magnitude used, both predictions, and their probabilities. Explain whether visual changes and prediction changes mean the same thing.

Results to retain

Items to record and points to check
Test Index and noise conditions
Original and noisy images
Original predictions and per-Class probabilities
Predictions and per-Class probabilities for noisy images

Points to check

  • Did you change only the image while keeping the scaler and classifier fixed?