Data Science Internship — Task 3, Prodigy InfoTech
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.
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.csvis 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.
- Python 3
- pandas, numpy
- scikit-learn (decision tree, random forest, grid search, metrics)
- matplotlib, seaborn
.
├── 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
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.pyWritten with # %% cell markers, so it also runs cell-by-cell in VS Code
(Jupyter extension) or a Jupyter notebook.
- Exact duplicate rows removed
pdays == -1(never previously contacted) split into awas_previously_contactedflag plus a capped numeric column, instead of feeding a placeholder-1straight into the model- Added a
balance_bucketfeature (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
durationexcluded 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
DecisionTreeClassifier, tuned viaGridSearchCVovercriterion,max_depth,min_samples_leaf, andmin_samples_split, scored on F1 under stratified 5-fold CVclass_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
RandomForestClassifiercomparison (300 trees) to sanity check whether an ensemble meaningfully beats the single tuned tree
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.
- 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
durationgives 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.
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