Wine Quality Analysis - Modern ML Approach

A comprehensive machine learning analysis of Portuguese “Vinho Verde” wine quality using modern gradient boosting models and explainable AI techniques.
Project Overview
This project analyzes wine quality based on physicochemical properties using advanced machine learning techniques. The analysis has been completely modernized with state-of-the-art models and interactive visualizations.
Dataset: UCI Machine Learning Repository - Wine Quality Data
- Red wine: 1,599 samples
- White wine: 4,898 samples
- Total: 6,497 wines with 11 physicochemical features
Target: Quality score (0-10, rated by wine experts)
Advanced Machine Learning Models
- XGBoost - Industry-standard gradient boosting
- LightGBM - Fast and efficient boosting algorithm
- CatBoost - Minimal hyperparameter tuning required
- Comparison with traditional models (SVM, Decision Trees, Random Forest)
Explainable AI (XAI)
- SHAP values - Understand which features drive predictions
- Feature importance - Ranking of most influential variables
- Model interpretability - Transparent decision-making
- Multi-class Classification - Predict exact quality scores (4-8)
- Binary Classification - Classify as “Good” (7-8) vs “Not Good” (4-6)
- Regression - Continuous quality score prediction
Unsupervised Learning
- K-Means Clustering - Discover natural wine groupings
- Dimensionality Reduction - PCA and UMAP visualizations
- Interactive 2D/3D plots - Explore wine similarity
Key Results
| Model |
Test Accuracy |
Cross-Val Mean |
| LightGBM |
~72% |
~71% |
| CatBoost |
~71% |
~70% |
| XGBoost |
~70% |
~69% |
| Random Forest (Baseline) |
~68% |
~67% |
Top Predictive Features:
- Alcohol content (strongest positive predictor)
- Volatile acidity (negative predictor)
- Chlorides (negative predictor)
- Sulphates (positive predictor)
- Density (negative predictor)
Installation & Setup
Install Dependencies
# Clone the repository
git clone https://github.com/priankr/wine-quality-machine-learning.git
cd wine-quality-machine-learning
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install required packages
pip install -r requirements.txt
Running the Analysis
Option 1: Jupyter Notebook (Recommended)
# Start Jupyter Notebook
jupyter notebook
# Open wine-quality-ml-updated.ipynb
# Run all cells to see the complete analysis
Option 2: View Results Online
Visit the Live Dashboard to explore interactive visualizations and predictions without running any code!
Project Structure
wine-quality-machine-learning/
├── wine-quality-ml-updated.ipynb # Modern ML analysis (NEW)
├── wine-quality-ml.ipynb # Original analysis (renamed)
├── winequality-red.csv # Red wine dataset
├── winequality-white.csv # White wine dataset
├── requirements.txt # Python dependencies
├── docs/ # GitHub Pages site
│ ├── index.html # Interactive dashboard
│ ├── exports/ # Model outputs & data
│ │ ├── model_results.json
│ │ ├── feature_importance.json
│ │ ├── stats.json
│ │ └── ...
│ └── *.html # Interactive Plotly charts
└── README.md # This file
Analysis Methodology
1. Data Preprocessing
- Outlier removal using Z-score method (|z| > 3)
- Feature engineering (total acidity, sulfur ratios, etc.)
- Train-test split (70/30)
- Standardization for model compatibility
2. Exploratory Data Analysis
- Correlation analysis
- Distribution analysis
- Interactive visualizations
3. Model Training & Evaluation
- Multiple model comparison
- Cross-validation (5-fold)
- Hyperparameter tuning
- Comprehensive metrics (accuracy, precision, recall, F1)
4. Model Interpretation
- SHAP value analysis
- Feature importance ranking
- Individual prediction explanations
5. Clustering Analysis
- Optimal cluster discovery (elbow method)
- Cluster characterization
- 2D visualization (PCA, UMAP)
Key Insights
- Gradient boosting models significantly outperform traditional Random Forest (~4% improvement)
- Binary classification (Good vs Not Good) achieves higher accuracy (~80%)
- Regression approach provides continuous estimates with low RMSE
Wine Quality Factors
- Alcohol content is the strongest quality predictor (positive correlation)
- Volatile acidity strongly predicts lower quality
- Wine type (red vs white) influences quality patterns
- 4 natural clusters discovered with distinct flavor profiles
Business Applications
- Quality control automation
- Recipe optimization
- Consumer preference prediction
- Anomaly detection for exceptional wines
References
- Original Dataset: P. Cortez, A. Cerdeira, F. Almeida, T. Matos and J. Reis. Modeling wine preferences by data mining from physicochemical properties. In Decision Support Systems, Elsevier, 47(4):547-553, 2009.
- UCI Repository: Wine Quality Data Set
- Original Kaggle Project: Wine Quality ML Classification
License
This project is open source and available under the MIT License.
Author
Prian Ravichandar
If you find this project useful, please consider giving it a star!
View Live Dashboard
评论