Decision Tree এমন একটি Machine Learning algorithm যা series of questions বা decision rules ব্যবহার করে prediction করে।
এর structure অনেকটা মানুষের decision-making flow-এর মতো।
Example
ধরুন আমরা predict করতে চাই একটি delivery late হবে কি না।
Distance > 5 km?
│
├── Yes → Traffic High?
│ ├── Yes → Late
│ └── No → Moderate Risk
│
└── No → On Time
প্রতিটি question একটি split।
Tree এমন feature এবং threshold খুঁজে বের করার চেষ্টা করে যা data-কে usefulভাবে separate করতে পারে।
Tree কীভাবে তৈরি হয়?
ধরুন features:
Distance
Traffic
Order Value
Restaurant Load
Weather
Algorithm বিভিন্ন possible split evaluate করতে পারে:
Distance > 5?
Traffic = High?
Restaurant Load > 20?
তারপর যে split target-কে সবচেয়ে ভালো separate করে সেটি choose করে।
এরপর একই process child nodes-এ repeat হয়।
Classification Tree
Classification-এ node কতটা mixed সেটা measure করার জন্য common criteria:
Gini Impurity
Entropy
Gini Impurity:
$$\text{ Gini } = 1 - \sum_{k}p_{k}^{2}$$যেখানে:
p_k = class k-এর proportion
Pure Node
ধরুন একটি node-এর সব observations:
Late
Late
Late
Late
এখানে node completely pure।
তাই impurity low।
কিন্তু:
Late
On Time
Late
On Time
mixed node হওয়ায় impurity বেশি।
Tree এমন splits prefer করে যা child nodes-কে বেশি pure করে।
Regression Tree
Regression Tree classification class predict করে না।
Numerical value predict করে।
উদাহরণ:
ETA = 34.7 minutes
Regression tree সাধারণত এমন split খোঁজে যা child nodes-এর prediction error বা variance কমায়।
Advantages
সহজে visualize ও explain করা যায়
nonlinear relationship capture করতে পারে
feature interactions naturally capture করে
scaling সাধারণত দরকার হয় না
numerical ও categorical patterns handle করতে পারে
Problems
single tree সহজে overfit করে
high variance হতে পারে
training data-তে ছোট change হলে পুরো tree বদলে যেতে পারে
deep tree generalization খারাপ করতে পারে
Overfitting Control
Common hyperparameters:
max_depth
min_samples_split
min_samples_leaf
max_leaf_nodes
এগুলো tree-এর complexity control করে।
Interview-ready Explanation
A Decision Tree makes predictions by recursively splitting
the data using feature-based rules.
For classification, it often uses criteria such as
Gini impurity or entropy to find useful splits.
For regression, it usually chooses splits that reduce
prediction error or variance.
Decision Trees are easy to interpret and capture nonlinear
relationships and interactions, but a single deep tree can
easily overfit and have high variance.