Overview • Dataset • Methodology • Results • Run Project
Academic Project — STQD6324 Data Management
A multiclass classification project using PySpark MLlib to compare Logistic Regression, Decision Tree and Random Forest models on the Iris dataset, with cross-validation and hyperparameter tuning.
This project demonstrates an end-to-end multiclass classification workflow using PySpark MLlib:
flowchart LR
A[Data Loading & Preprocessing] --> B[Feature Engineering]
B --> C[Train-Test Split]
C --> D[Model Training & Hyperparameter Tuning]
D --> E[Performance Evaluation]
E --> F[Model Comparison]
Iris Dataset (Fisher, 1936)
- Source: GitHub
↗️ - Samples: 150 iris flowers
- Features: 4 continuous measurements
- Sepal length (cm)
- Sepal width (cm)
- Petal length (cm)
- Petal width (cm)
- Target:
species
| Setosa | Versicolor | Virginica |
|---|---|---|
![]() |
![]() |
![]() |
Three classification algorithms were implemented and compared:
| Model | Purpose |
|---|---|
| Logistic Regression | Linear classification model used as a baseline |
| Decision Tree | Tree-based model that captures nonlinear decision boundaries |
| Random Forest | Ensemble of decision trees designed to improve predictive performance and reduce overfitting |
Each model was optimized using 5-fold cross-validation and grid search over selected hyperparameters:
- Logistic Regression:
regParam,elasticNetParam,maxIter - Decision Tree:
maxDepth,impurity,minInstancesPerNode - Random Forest:
numTrees,maxDepth,maxBins
Models were evaluated using Accuracy, Weighted Precision, Weighted Recall and F1-Score to assess overall classification performance across the three classes.
🎯 Accuracy 🔍 Weighted Precision 📈 Weighted Recall ⚖️ F1-Score
iris_classification_pyspark.ipynb
├── 1. Environment Setup and Imports
├── 2. Load Iris Dataset
├── 3. Data Preprocessing
├── 4. Train-Test Split
├── 5. Model Implementation with Hyperparameter Tuning
│ ├── Logistic Regression
│ ├── Decision Tree
│ └── Random Forest
├── 6. Model Evaluation
├── 7. Predictions on Test Data
├── 8. Comparative Analysis
└── 9. Cleanup| Model | Accuracy | Precision | Recall | F1-Score |
|---|---|---|---|---|
| Logistic Regression | 0.97 | 0.97 | 0.97 | 0.97 |
| Decision Tree | 0.91 | 0.94 | 0.91 | 0.91 |
| Random Forest | 0.97 | 0.97 | 0.97 | 0.97 |
Note
- Top Performers: Logistic Regression and Random Forest achieved the strongest overall test performance.
- Feature Importance: Petal length and petal width were the most influential features for classification.
- Class Separability: Setosa was easily separated, while most classification errors occurred between Versicolor and Virginica.
The confusion matrices show the classification performance of each model across the three Iris species. Most errors occur between Versicolor and Virginica, while Setosa is more easily distinguished.
Random Forest feature importance indicates that petal measurements contributed most strongly to the classification, while the sepal measurements had comparatively lower importance.
This project was developed in Google Colab using PySpark, providing a convenient environment for running Apache Spark without a local Spark installation.
- Download
iris_classification_pyspark.ipynb. - Open Google Colab.
- Upload the notebook.
- Connect to a runtime using Runtime → Connect.
- Install the required libraries:
!pip install pyspark pandas matplotlib seaborn- Run the notebook cells sequentially.
Alternative: Local Jupyter Notebook
For local execution, ensure Java JDK 8 or 11 is available for the Spark runtime.
- Download the notebook file :
iris_classification_pyspark.ipynb - Open the notebook in Jupyter
- Install the required libraries :
!pip install pyspark pandas matplotlib seabornThis project was completed as part of the STQD6324 Data Management course at Universiti Kebangsaan Malaysia.



