Skip to content

seyyed-erfan-mohammadi/Emotion_Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Facial Emotion Classification using PCA and SVM

image

This project demonstrates a classic pattern recognition pipeline for facial emotion classification using Principal Component Analysis (PCA) and Support Vector Machines (SVM). It was originally developed as part of a university coursework assignment and focuses on distinguishing between happy and neutral facial expressions.

By leveraging PCA for dimensionality reduction and SVM for classification, the model learns to extract the most informative features (Eigenfaces) and classify them with high accuracy.


🧠 Project Summary

The goal of this project is to classify facial images as either happy or neutral using a combination of Principal Component Analysis (PCA) and Support Vector Machines (SVM). The dataset consists of grayscale facial images labeled with their corresponding emotion. The processing pipeline follows a structured approach: first, the images are loaded and preprocessed to ensure consistency. Then, the central region of the face is cropped to eliminate distractions such as hair, clothes, and ears. Each 2D image is then flattened into a 1D vector to make it compatible with machine learning models. PCA is applied to reduce the dimensionality of the data and extract the most significant features (principal components). These features are then used to train an SVM classifier, which learns to distinguish between the two emotional states. Finally, the model’s performance is evaluated using standard metrics and a confusion matrix to assess classification accuracy and reliability.


🚀 How It Works

1. Load Images

Images are loaded from separate folders for each emotion. The script converts them to grayscale.

2. Preprocess (Crop Faces)

To focus on the facial region, the images are cropped to exclude irrelevant areas like hair, ears, and clothes.

3. Flatten Images

Cropped 2D images are flattened into 1D vectors for processing.

4. PCA for Feature Extraction

  • PCA is applied separately to each emotion class to reduce dimensionality and capture the main facial features (Eigenfaces).
  • 15 principal components are retained, preserving ~90% of variance.

5. SVM Classification

  • Features from both emotions are concatenated.
  • A support vector machine (SVC) is trained on the PCA-transformed vectors.
  • Classification is evaluated using precision, recall, F1-score, and accuracy.

💡 What You Can Learn

  • Basics of face image preprocessing and feature engineering.
  • How PCA works for image data.
  • Training and evaluating a classification model using SVM.
  • Performance metrics interpretation for classification tasks.

About

A machine learning project that classifies facial emotions (happy vs. neutral) using Principal Component Analysis for feature extraction and Support Vector Machine for classification.

Topics

Resources

License

Stars

Watchers

Forks

Contributors