Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Bank Marketing Decision Tree Classifier

Data Science Internship — Task 3, Prodigy InfoTech

📌 Task

Build a decision tree classifier to predict whether a customer will subscribe to a term deposit, based on demographic and campaign-behavioral data, using the Bank Marketing dataset from the UCI Machine Learning Repository.

📊 Dataset

Bank Marketing dataset — UCI Machine Learning Repository. Records a Portuguese bank's direct-marketing phone campaigns and whether each client subscribed to a term deposit.

Column Description
age Client age
job Type of job
marital Marital status
education Education level
default Has credit in default?
balance Average yearly account balance
housing Has housing loan?
loan Has personal loan?
contact Contact communication type
day, month Last contact date
duration Last contact duration (seconds)
campaign # contacts during this campaign
pdays Days since last contact from a previous campaign (-1 = never)
previous # contacts before this campaign
poutcome Outcome of previous campaign
y Target — subscribed to a term deposit? (yes/no)

bank_marketing.csv is a synthetic stand-in built to match the real UCI dataset's columns, delimiter (;), and rough relationships. Swap in the real file before final submission — no code changes needed.

🛠️ Tech Stack

  • Python 3
  • pandas, numpy
  • scikit-learn (decision tree, random forest, grid search, metrics)
  • matplotlib, seaborn

📁 Repository Structure

.
├── generate_sample_data.py       # creates the sample bank_marketing.csv
├── bank_marketing.csv            # dataset (swap with the real file)
├── decision_tree_classifier.py   # cleaning + EDA + model + evaluation
├── 01_target_distribution.png … 09_decision_tree_plot.png
└── README.md

▶️ How to Run

pip install pandas numpy matplotlib seaborn scikit-learn

# (optional) regenerate the sample dataset
python generate_sample_data.py

# run the full pipeline
python decision_tree_classifier.py

Written with # %% cell markers, so it also runs cell-by-cell in VS Code (Jupyter extension) or a Jupyter notebook.

🧹 Data Cleaning & Preparation

  • Exact duplicate rows removed
  • pdays == -1 (never previously contacted) split into a was_previously_contacted flag plus a capped numeric column, instead of feeding a placeholder -1 straight into the model
  • Added a balance_bucket feature (negative / low / medium / high) — a coarse bucket that can let a shallow tree split faster than the raw continuous balance
  • Categorical "unknown" values kept as their own category rather than dropped
  • Categorical columns label-encoded
  • duration excluded from the model: it's only known after a call is placed, so keeping it would leak post-call information into what should be a pre-call "who to target" prediction

🌳 Modeling Approach

  • DecisionTreeClassifier, tuned via GridSearchCV over criterion, max_depth, min_samples_leaf, and min_samples_split, scored on F1 under stratified 5-fold CV
  • class_weight="balanced" to address class imbalance
  • Evaluated with accuracy, precision, recall, F1, ROC AUC, confusion matrix, and ROC curve
  • Feature importance chart and a depth-limited tree diagram for interpretability
  • Added a quick RandomForestClassifier comparison (300 trees) to sanity check whether an ensemble meaningfully beats the single tuned tree

📈 Results (on sample data — rerun against the real dataset for final numbers)

Printed at the end of the run: best grid-search parameters, cross-validated F1, and full test-set classification report for both the tuned tree and the random forest comparison.

💡 Key Insights

  • Previous campaign outcome is consistently the strongest predictor — clients who subscribed before are far more likely to subscribe again.
  • Job type matters: students and retirees subscribe at higher rates than working-age professionals.
  • Existing loans (housing or personal) correlate with lower subscription likelihood.
  • Dropping duration gives a more honest picture of what's predictable before placing the call, which is the version of this model that's actually useful for campaign targeting.

🔗 About

Recreated and extended (Random Forest comparison, extra engineered features, restructured cleaning) from the Prodigy InfoTech Data Science Task 3 brief — decision tree classification on the Bank Marketing dataset.

#DataScience #Python #MachineLearning #DecisionTree #ProdigyInfoTech #Internship

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages