This repository contains the data analysis and machine learning models developed to address a classification problem, likely related to predicting customer behavior or status (e.g., churn prediction, lead conversion). The project focuses on building and evaluating two common classification algorithms: Logistic Regression and Random Forest, with a particular emphasis on handling class imbalance. This was a collaborative project with 3 other researchers.
https://www.canva.com/design/DAGrZYPOAsI/evIriptCYwT2RqwptJe1MA/edit
The primary goal of this project was to:
- Perform exploratory data analysis (EDA) to understand the dataset.
- Build robust classification models to predict a target variable.
- Compare the performance of Logistic Regression and Random Forest.
- Address the challenge of class imbalance in the dataset to ensure fair and accurate predictions across all classes.
- Data Loading & Preprocessing: Initial handling of the dataset, preparing it for modeling.
- Class Imbalance Handling: Implementation of
class_weight='balanced'in both Logistic Regression and Random Forest models to mitigate bias towards the majority class. - Logistic Regression:
- Trained and evaluated both without and with class weighting.
- Performance metrics (precision, recall, f1-score, accuracy) and confusion matrices were meticulously analyzed to show the impact of balancing.
- ROC curve and AUC score were used for overall model evaluation.
- Random Forest Classifier:
- Trained with
class_weight='balanced'for robust performance. - Evaluated using a comprehensive classification report, confusion matrix, and ROC curve with AUC.
- Trained with
- Model Comparison: A direct comparison of the two models' effectiveness, particularly in handling the minority class.
- Logistic Regression: Showed significant improvement in identifying the minority class (recall increased from ~0.58 to ~0.80) when
class_weight='balanced'was applied, while maintaining a strong overall AUC of ~0.931. - Random Forest: Achieved exceptional performance, with an AUC of 1.00, indicating a near-perfect ability to distinguish between classes. The confusion matrix also confirmed extremely high precision and recall for both classes (e.g., 715 true negatives, 287 true positives, with minimal false positives/negatives). This model demonstrated superior predictive power on this dataset.
Spam_Email_Classification_EDA.ipynb: The main Jupyter Notebook containing all the code for data loading, preprocessing, model training, evaluation, and visualization.README.md: This file.requirements.txt: (To be added) Lists all necessary Python libraries for running the notebook.
To run this analysis locally, please follow these steps:
- Clone the repository:
git clone [https://github.com/your-username/your-repo-name.git](https://github.com/your-username/your-repo-name.git) cd your-repo-name - Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: `venv\Scripts\activate`
- Install dependencies:
(You will need to create a
requirements.txtfile based on the libraries used in your notebook, e.g., pandas, scikit-learn, matplotlib, seaborn.)pip install -r requirements.txt
- Launch Jupyter Notebook:
jupyter notebook
- Open
project3_draft_final.ipynband run the cells.
- Python 3.x
- Jupyter Notebook
- Pandas (for data manipulation)
- NumPy (for numerical operations)
- Scikit-learn (for machine learning models and metrics)
- Matplotlib (for plotting)
- Seaborn (for enhanced visualizations)
For any questions or suggestions, feel free to open an issue or contact bryanmejiaeducation@gmail.com.