Lesson 49 of 60
pythonDecision Trees and Random Forests
30 minutes
Course progress82%
Decision Trees & Random Forests
Tree‑based models are intuitive, handle mixed data types, and require little preprocessing.
Decision Tree basics
- Splits data based on feature thresholds.
- Uses impurity measures: Gini, entropy (information gain).
Training a Decision Tree with scikit‑learn
from sklearn.tree import DecisionTreeClassifier
sklearn tree
clf = DecisionTreeClassifier(max_depth=, random_state=)
clf.fit(X_train, y_train)
plt.figure(figsize=(,))
tree.plot_tree(clf, filled=, feature_names=X.columns, class_names=[,])
plt.show()