First Supervised Learning: Classification
Past preprocessing and EDA, I moved on to the model stage. I learned classification with two real datasets.
Decision Tree — Loan Approval Prediction
I predicted approval/rejection (loan_status) with loan.csv.
from sklearn.tree import DecisionTreeClassifier, plot_tree
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoderI went through the following flow.
- Filled categorical missing values with the mode and numeric with the median, and converted strings to numbers with
LabelEncoder - Split train and test with
train_test_split - Drew the tree with
plot_treeto see the decision process - Evaluated with accuracy,
confusion_matrix,classification_report - Interpreted which variables drove the decision via feature importance.
cibil_scorewas the main one - Compared overfitting: larger
max_depthraises train accuracy but hurts generalization
The appeal of trees is that they can explain "why did it predict this?"
Ensembles — Telco Churn Prediction
I went a step further with Telco-Customer-Churn.
- Converted
TotalChargesviapd.to_numeric(errors='coerce')and then handled missing values - Mapped
ChurnYes/No to 1/0 - One-hot encoded with
get_dummiesanddrop_first=True, and aligned test columns to train withreindex. This is a basic guard against leakage - Scaled only numeric columns with
StandardScaler - Compared performance of bagging and boosting ensembles in addition to a single tree
Takeaway
Key point
What stuck most was the principle "align test to train." Success hinges less on the model than on preparing data without leakage. I also watched performance rise moving from a single model to an ensemble.