Skip to content

Yehia-Alsaeed/rff-wine-quality-classifier

Repository files navigation

RFF Wine Quality Classifier

A fully functional PyTorch machine learning pipeline that applies Random Fourier Features to white wine quality prediction. The project uses a fixed random Fourier mapping as a kernel-inspired feature layer, then trains a small neural network classifier on top of the transformed tabular features.

The main experiment maps wine quality scores into three classes and compares a baseline RFF model against four tuned variants. A second binary experiment evaluates the same tuned RFF idea for identifying high-quality wine.

Tech Stack & Core Skills

  • Deep Learning Framework: PyTorch
  • Machine Learning Concepts: Kernel Approximation, Random Fourier Features (RFF), Tabular Classification
  • Data Engineering: Feature Standardization, Stratified Splitting, Data Preprocessing
  • Model Optimization: Macro F1 Evaluation, Early Stopping, Hyperparameter Comparison
  • Monitoring: TensorBoard

Architecture & Methodology

Dataset & Preprocessing The pipeline uses a white wine quality dataset containing physicochemical features (acidity, residual sugar, chlorides, density, pH, sulphates, alcohol) and a quality score.

  • Drops duplicate rows and confirms no missing values are present.
  • Maps the original quality score into classification labels (0: Low quality <= 5, 1: Medium quality = 6, 2: High quality >= 7).
  • Uses stratified train, validation, and test splits.
  • Standardizes features with StandardScaler fitted exclusively on the training set.

Model Architecture The model transforms the tabular inputs using fixed random frequencies and phases (cosine and sine features), then trains a fully connected head:

Standardized wine features
  -> fixed Random Fourier Feature mapping
  -> fully connected neural head
  -> class logits
  -> cross-entropy loss

The RFF layer keeps its random projection fixed; only the neural classifier head is trained with gradient descent.

Experimental Variations

Model Main Change
Baseline RFF RFF dimension 64, hidden dimension 64, sigma 1.0, learning rate 1e-3.
Variation 1 Same baseline architecture with a smaller learning rate of 5e-4.
Variation 2 Adds L2 regularization with weight decay 1e-4.
Variation 3 Higher-capacity RFF model with 256 RFF features, larger hidden layer, stronger regularization, and early stopping.
Variation 4 Tuned RFF model with 128 RFF features, sigma 0.5, light regularization, and early stopping.

Results & Visuals

RFF wine quality results chart

Three-Class Classification Results:

Model Val Accuracy Test Accuracy Val Macro F1 Test Macro F1
Baseline RFF 0.5076 0.4857 0.4795 0.4654
Variation 1 0.5479 0.5277 0.5153 0.5079
Variation 2 0.5361 0.5261 0.5034 0.5022
Variation 3 0.5983 0.5361 0.5705 0.5144
Variation 4 0.6067 0.5714 0.5861 0.5553

Variation 4 achieved the best test accuracy and test macro F1 among the three-class RFF experiments.

Binary High-Quality Classification Results:

Task Val Accuracy Test Accuracy Val Macro F1 Test Macro F1
High vs not-high wine quality 0.8084 0.7933 0.6399 0.6228

Repository Structure

rff_wine_quality_classifier.ipynb   Final RFF implementation pipeline
winequality-white.csv               White wine quality dataset
requirements.txt                    Python dependencies

Requirements

If you wish to run this pipeline locally:

  • Python dependencies can be installed via pip install -r requirements.txt.
  • Open rff_wine_quality_classifier.ipynb to execute the pipeline. The script expects winequality-white.csv to remain in the repository root.
  • Optional: Training logs can be viewed locally by running tensorboard --logdir runs.

About

PyTorch Random Fourier Features classifier for white wine quality prediction with 3-class and binary experiments.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors