MNIST Project Part 1: Feature Extraction, Density Estimation, and Bayesian Classification, Exercises of Pattern Classification and Recognition

This project involves using a subset of images from the mnist dataset for digit '3' and '7'. The goal is to perform feature extraction, density estimation, and bayesian classification. The data is stored in .mat files, and you'll be working on three tasks: feature extraction and normalization, density estimation using normal distributions, and bayesian decision theory for optimal classification with different prior probabilities. Submit your code and a report summarizing the results.

Typology: Exercises

2021/2022

Uploaded on 11/09/2022

vpm19091986
vpm19091986 🇺🇸

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Project Part 1 [10 points] Feature Extraction, Density Estimation and Bayesian
Classification (Due October 6, 11:59pm)
This part of the project uses a subset of images (with modifications) from the MNIST
dataset. The original MNIST dataset (http://yann.lecun.com/exdb/mnist/) contains
70,000 images of handwritten digits, divided into 60,000 training images and 10,000
testing images. We use only images for digit “3and digit 7” in this project. The data is
stored in “.mat” files. You may use the following piece of code to read the dataset in
Python (or you may use the load filename command in Matlab, since these are .mat files):
import scipy.io
data = scipy.io.loadmat(‘matlabfile.mat’)
Following are the statistics for the data you are going to use:
Number of samples in the training set: "3": 5713; "7": 5835
Number of samples in the testing set : "3": 1428; "7": 1458
You will practice doing the following three tasks in this project:
Task 1. Feature extraction and normalization
In the .mat file, each image is stored as a 28x28 array of pixels. The pixel values range
from 0 to 255. For each image i, compute two features:
1. Skewness of image ki This is measure of symmetry of the pixel values for i. For
more information, visit
https://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
2. Ratio of brighter to darker pixels ri using a threshold T.
We further normalize the features in the following way, before starting any subsequent
tasks. Using the feature representations of all the training images from both classes (each
image i is now viewed as a 2-d vector, Xi = [ki, ri]t, as explained), compute the mean Mj
and standard deviation Sj, j=1,2, for the first and the second feature, respectively. Mj and
Sj will be used to normalize all the feature vectors (both training and testing): for each
feature vector Xi representing image i, a normalized feature vector Yi will be computed as
Yi = [ y1i, y2i]t = [ (ki M1)/S1, (ri M2)/S2]t
This Yi is the final feature representation for image i and will be used for subsequent
steps.
Task 2. Density estimation
pf2

Partial preview of the text

Download MNIST Project Part 1: Feature Extraction, Density Estimation, and Bayesian Classification and more Exercises Pattern Classification and Recognition in PDF only on Docsity!

Project Part 1 [1 0 points] Feature Extraction, Density Estimation and Bayesian Classification (Due October 6, 11:59pm) This part of the project uses a subset of images (with modifications) from the MNIST dataset. The original MNIST dataset (http://yann.lecun.com/exdb/mnist/) contains 70,000 images of handwritten digits, divided into 60,000 training images and 10, testing images. We use only images for digit “ 3 ” and digit “ 7 ” in this project. The data is stored in “.mat” files. You may use the following piece of code to read the dataset in Python (or you may use the load filename command in Matlab, since these are .mat files): import scipy.io data = scipy.io.loadmat(‘matlabfile.mat’) Following are the statistics for the data you are going to use: Number of samples in the training set: " 3 ": 5713 ; " 7 ": 5835 Number of samples in the testing set : " 3 ": 1428 ; " 7 ": 1458 You will practice doing the following three tasks in this project: Task 1. Feature extraction and normalization In the .mat file, each image is stored as a 28x28 array of pixels. The pixel values range from 0 to 255. For each image i, compute two features:

  1. Skewness of image ki – This is measure of symmetry of the pixel values for i. For more information, visit https://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
  2. Ratio of brighter to darker pixels ri using a threshold T. We further normalize the features in the following way, before starting any subsequent tasks. Using the feature representations of all the training images from both classes (each image i is now viewed as a 2 - d vector, Xi = [ki, ri]t, as explained), compute the mean Mj and standard deviation Sj, j=1,2, for the first and the second feature, respectively. Mj and Sj will be used to normalize all the feature vectors (both training and testing): for each feature vector Xi representing image i, a normalized feature vector Yi will be computed as Yi = [ y1i, y2i]t^ = [ (ki – M 1 )/S 1 , (ri – M 2 )/S 2 ]t This Yi is the final feature representation for image i and will be used for subsequent steps. Task 2. Density estimation

We assume in the 2-d feature space of Yi defined above, samples from each class follow a normal distribution. Using the MLE method, you will need to estimate the parameters for the 2-d normal distribution for each class/digit, using the respective training data for that class/digit. Note: You will have two distributions, one for each digit. Task 3. Bayesian Decision Theory for optimal classification Use the estimated distributions for doing minimum-error-rate classification, for the following two cases respectively: Case 1: Assume that the prior probabilities are the same (i.e., P( 3 ) = P( 7 ) =0.5). Case 2: Assume that the prior probabilities are: P( 3 ) = 0.3, P( 7 ) = 0.7. For both cases, report the error rate of the optimal classifier, for the training set and the testing set respectively where error rate is defined as ratio of number of incorrect predictions to total number of samples. Task 4. Try different threshold values for the feature ri Do all the above steps for two values of threshold T for ri feature- Case 1: T = 150 Case 1: T = 200 What to submit:

  1. Your code for doing the above.
  2. A report summarizing the results, e.g., the estimated parameters of the distributions, the training and testing error probabilities. Include in your report any intermediate results that you deem helpful for illustrating the partial results. Note: There is no minimum or maximum length requirement for the report. Writing the report is the opportunity for you to reflect on your understanding of the problems/tasks through organizing your results. The data files for the project are uploaded in the Files/Assignments folder: train_data.mat test_data.mat