Decision Tree
A decision tree is a machine learning model that makes predictions by asking a sequence of yes/no questions about the features, following branches until it reaches an answer at a leaf.
Data & AI
Each internal node tests a feature ('Is age > 30?'), each branch is an outcome, and each leaf gives a prediction. Trees are easy to read and interpret because you can literally follow the path of decisions.
It works just like a flowchart or a game of 20 questions. Decision trees can overfit if grown too deep, which is why many trees are often combined into a random forest for better accuracy.
Examples
Python
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier(max_depth=2).fit(X_train, y_train)
print("depth:", clf.get_depth())Output:
depth: 2