João Gilberto Saraiva

software engineer | professor | writer


Cat vs. Dog: A Machine Learning Experiment | João Gilberto Saraiva

Cat vs. Dog: A Machine Learning Experiment

07-12-2025

“Cat vs. Dog” is the “Hello World” of Computer Vision. But solving it is one thing; understanding the mathematical and statistical foundations behind the solution is another.

For my final project in IMD3002 - Supervised Machine Learning at Artificial Intelligence program at UFRN, instructed by Prof. João Carlos Xavier Junior, I didn’t just trained models. We build a complete, rigorous scientific framework to test the fundamentals of Machine Learning.

Here is how I broke down the workflow into a series of sequential experiments.

The Objective

The goal was to classify images of specific breeds (Miniature Pinscher/English Setter vs. Birman/Ragdoll) by exercising every fundamental stage of a classic ML pipeline: from raw pixels to statistical validation.

Step 1: Feature Extraction (Beyond Pixels)

Raw images are noisy and high-dimensional. To make them digestible for classical algorithms, I implemented two distinct visual descriptors:

Step 2: Dimensionality Reduction

With high-dimensional feature vectors, the “Curse of Dimensionality” becomes a real threat. I applied PCA (Principal Component Analysis) to project the data into a lower-dimensional space, balancing computational efficiency with information retention.

Step 3: Model Training & Tuning

I implemented and compared five distinct classes of algorithms to see how they handled the visual data:

Each model underwent rigorous hyperparameter tuning (GridSearch) to ensure we were comparing the best versions of each.

Step 4: Statistical Evaluation

This is where many projects stop, but scientific rigor requires more than just comparing average accuracy. I applied the Friedman Test to determine if the differences in performance were statistically significant and the Nemenyi Post-hoc Test to pinpoint exactly which models outperformed the others.

The Verdict

The statistical analysis revealed that for this specific dataset, an MLP combined with LBP features offered the best trade-off between predictive power and computational cost, significantly outperforming shape-based approaches (HOG).

You can explore the full step-by-step workflow, organized in sequential Jupyter Notebooks, on my GitHub: https://github.com/0jonjo/cat_dog_ml

image

Image: “Ai is… Banner”, Rick Payne and Team. Better Images of AI, Creative Commons 4.0