Welcome to the Lead Conversion Prediction repository!
This project tackles a classic business problem: predicting whether a potential lead will convert into a successful conversion (1) or not (0). It serves as a practical implementation of data generation, feature engineering, and handling imbalanced datasets using ensemble methods like Random Forest and XGBoost.
If you are exploring the Jupyter Notebook (LEADS_XGboost.ipynb), here is a simple breakdown of the logic and flow:
Since real-world CRM data is often private, the first step is building our own playground.
- Using the
Fakerlibrary andnumpy, the code simulates 500 random leads. - It assigns realistic features to each lead:
name,budget,interest_level(1-10),lead_source(Website, Referral, etc.), andfollow_up_count. - We deliberately generate the target variable (
converted) with a realistic 70/30 splitโmeaning 70% of leads don't convert, and 30% do.
Machine learning models speak numbers, not text.
- The
lead_sourcecolumn contains categorical data (e.g., 'Email', 'Website. - We use One-Hot Encoding (
pd.get_dummies) to split these sources into their own independent binary columns (True/False or 1/0) so the model can correctly weigh the success rate of each specific source.
- The data is split into an 80/20 train-test ratio.
- A
RandomForestClassifieris trained first as a baseline. - The Catch: When we test it, the overall accuracy might look okay (around 65%), but looking closely at the
classification_report, the model is heavily biased. Because there are way more0s (no conversion) than1s (conversion), the model takes the easy way out and mostly predicts0.
To fix the bias, we bring in XGBClassifier.
- Instead of letting the model ignore the minority class (the successful conversions), we calculate the exact ratio of failures to successes.
- We pass this ratio into XGBoost using the
scale_pos_weightparameter. - The Logic: This acts as a penalty multiplier. We are essentially telling the decision trees: "Pay X times more attention to the minority class so you don't just guess 0 every time!".
- Python (Core logic)
- Pandas & NumPy (Data manipulation and mathematical operations)
- Faker (Generating realistic synthetic data)
- Scikit-Learn (Preprocessing, Random Forest, and Evaluation Metrics)
- XGBoost (Advanced gradient boosting for the final model)
- Clone the repository to your local machine.
- Ensure you have the required libraries installed:
pip install pandas numpy scikit-learn xgboost faker
Open LEADS_XGboost.ipynb in Jupyter Notebook or Google Colab and run the cells sequentially to generate the data and train the models.
Feel free to explore the code, fork the repo, or reach out if you have any suggestions!