This project uses Machine Learning to predict the quality of red wine based on its physicochemical properties. The model is trained using historical wine quality data and can predict the quality score of new wine samples.
The project demonstrates the complete machine learning workflow, including data preprocessing, model training, evaluation, model persistence, and making predictions using a saved model.
- Project Overview
- Objectives
- Dataset
- Technologies Used
- Machine Learning Workflow
- Project Structure
- Installation
- How to Run
- Model Performance
- Features
- What I Learned
- Future Improvements
- Requirements
- Author
Wine quality can be influenced by several chemical properties such as acidity, sugar content, alcohol percentage, pH, and sulphates. Instead of manually estimating wine quality, this project uses a supervised machine learning model to learn patterns from historical data and predict the quality of unseen wine samples.
This project was developed to strengthen my understanding of the end-to-end machine learning process using Python and Scikit-learn.
The objectives of this project are to:
- Load and explore the wine quality dataset.
- Prepare the data for machine learning.
- Train a machine learning model.
- Evaluate the model's performance.
- Save the trained model using Joblib.
- Load the saved model for future predictions.
- Predict the quality of new wine samples.
The dataset contains physicochemical properties of red wine along with a quality score assigned by wine experts.
- Fixed Acidity
- Volatile Acidity
- Citric Acid
- Residual Sugar
- Chlorides
- Free Sulfur Dioxide
- Total Sulfur Dioxide
- Density
- pH
- Sulphates
- Alcohol
- Quality
The target variable is the wine quality score predicted by the machine learning model.
- Python
- Pandas
- NumPy
- Scikit-learn
- Joblib
- Matplotlib
- Seaborn
- PyCharm
- Git
- GitHub
The project follows a standard machine learning workflow:
- Import required libraries.
- Load the dataset.
- Explore and understand the data.
- Clean and prepare the dataset.
- Separate features and target variable.
- Split the data into training and testing sets.
- Train the machine learning model.
- Evaluate model performance.
- Save the trained model.
- Load the saved model.
- Predict the quality of new wine samples.
This project uses Supervised Learning because the dataset contains both input features and the correct quality scores used during training.
Depending on the model selected during training, this project predicts wine quality using a regression algorithm. Different regression algorithms can be compared to determine which one performs best before selecting the final model.
Wine-Quality-Prediction/
│
├── data/
│ └── winequality-red.csv
│
├── models/
│ └── wine_quality_model.joblib
│
├── train.py
├── predict.py
├── README.md
├── requirements.txt
└── .gitignore
Clone the repository:
git clone https://github.com/Acacia21-code/Wine-Quality-Prediction.gitNavigate into the project folder:
cd Wine-Quality-PredictionInstall the required packages:
pip install -r requirements.txtpython train.pyThe training script will:
- Load the dataset
- Train the machine learning model
- Evaluate the model
- Save the trained model
Run:
python predict.pyExample output:
Model loaded from wine_quality_model.joblib
Sample 1 predicted quality: 5.84
Sample 2 predicted quality: 6.41
- Data preprocessing
- Machine learning model training
- Model evaluation
- Save trained model using Joblib
- Load saved model
- Predict quality of new wine samples
- Clean and reusable Python code
The trained Random Forest Regressor was evaluate on a held-out test set (20% of the data):
**Mean Squared Error (MSE):**0.301 **R2 Score:**0.540
An R2 of 0.54 means the model explains about 54% of the varience in wine quality scores based on physicochemical properties alone - a resonable result given wine quality also depends on subjective sensory factors (like taste and aroma) that are not in the chemical data.
Through this project, I learned:
- The complete machine learning workflow.
- The difference between supervised and unsupervised learning.
- How regression models predict numerical values.
- How to prepare datasets for machine learning.
- How to split data into training and testing sets.
- How to train and evaluate machine learning models.
- How to compare different algorithms to determine which performs best.
- How to save and load trained models using Joblib.
- How to make predictions using previously unseen data.
- The importance of reproducible and well-documented projects.
Some challenges encountered during the project included:
- Understanding the complete machine learning workflow.
- Learning when to use regression algorithms.
- Understanding model evaluation metrics.
- Organizing project files for GitHub.
- Learning how to save and reuse trained models.
These challenges provided valuable experience in practical machine learning development.
Possible improvements include:
- Compare multiple regression algorithms.
- Perform hyperparameter tuning.
- Build a Streamlit web application for predictions.
- Allow users to upload CSV files for batch predictions.
- Deploy the model online.
- Improve feature engineering.
- Add automated model evaluation reports.
Required Python packages:
pandas
numpy
scikit-learn
joblib
matplotlib
seaborn
Install them using:
pip install -r requirements.txtRecommended repository topics:
- python
- machine-learning
- scikit-learn
- pandas
- data-science
- regression
- predictive-modeling
- wine-quality
- joblib
- beginner-project
Mbali Simelane
Aspiring Data Scientist and Machine Learning Developer
This project was created as part of my machine learning learning journey and demonstrates the complete process of building, training, evaluating, and deploying a machine learning model using Python and Scikit-learn.