neck392/p3-wine-quality-keras-mlp32-16-huber-tuned
P3 Wine Quality Prediction - Keras MLP32-16 Huber Tuned
This repository contains a Keras-based MLP model developed for wine quality prediction.
The model predicts wine quality from 11 physicochemical input features. It first produces a continuous regression output and then applies threshold-based post-processing to convert the output into an integer wine quality label.
Model Summary
- Framework: TensorFlow / Keras
- Model type: Multi-Layer Perceptron
- Hidden layers: 32-16
- Activation: ReLU
- Loss function: Huber loss, delta=1.0
- Optimizer: Adam
- Learning rate: 0.001
- Batch size: 32
- Maximum epochs: 500
- Early stopping patience: 30
- Epochs trained: 84
- Target variable:
quality - Theoretical quality range: 0 to 10
- Actual quality range in the dataset: 3 to 9
Input Features
- fixed acidity
- volatile acidity
- citric acid
- residual sugar
- chlorides
- free sulfur dioxide
- total sulfur dioxide
- density
- pH
- sulphates
- alcohol
Preprocessing
The preprocessing pipeline follows the same experimental setting used during model development.
- 1st to 99th percentile clipping based on the training data
log1ptransformation for selected skewed features- StandardScaler normalization
- Keras MLP regression prediction
- Clipping continuous predictions to the 0-10 range
- Threshold-based integer quality conversion
Clipped Features
~~~text ['fixed acidity', 'volatile acidity', 'citric acid', 'residual sugar', 'chlorides', 'free sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates'] ~~~
Log-transformed Features
~~~text ['chlorides', 'volatile acidity', 'free sulfur dioxide', 'citric acid', 'residual sugar'] ~~~
Thresholds
The threshold values selected on the validation set are:
~~~text [3.5, 4.5, 5.65, 6.6, 7.5, 8.5] ~~~
Performance
Raw Regression Performance
Threshold-Tuned Integer Quality Performance
Model Selection Note
Although MLP168 achieved the lowest validation RMSE among raw regression models, this MLP32-16 Huber model was selected as the final single model because it achieved better threshold-tuned integer quality prediction performance on the validation set.
Repository Files
Example Usage
~~~python from inference import predict_quality
sample = { "fixed acidity": 7.0, "volatile acidity": 0.27, "citric acid": 0.36, "residual sugar": 20.7, "chlorides": 0.045, "free sulfur dioxide": 45.0, "total sulfur dioxide": 170.0, "density": 1.001, "pH": 3.00, "sulphates": 0.45, "alcohol": 8.8 }
result = predict_quality(sample) print(result) ~~~
Limitations
The dataset is concentrated around middle quality scores, especially 5 and 6. As a result, predictions for rare extreme quality scores may be less reliable.
