Explainable classification rules
Need an interpretable baseline for labeled tabular data.
Scikit-Learn · Class
A supervised decision-tree classifier that learns feature-based rules for binary or multiclass prediction. Its split criterion, growth limits, weighting, randomness, and pruning behavior are configurable.
The classifier recursively chooses feature-based splits to form a tree, using a selectable impurity or information-gain criterion. Training stops according to depth, sample, leaf, impurity, or leaf-count constraints; the fitted tree then predicts classes and probabilities for new samples.
class sklearn.tree.DecisionTreeClassifier(*, criterion='gini', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, class_weight=None, ccp_alpha=0.0, monotonic_cst=None)| Name | Type | Description |
|---|---|---|
criterion | {"gini", "entropy", "log_loss"} | Split-quality function: gini, entropy, or log_loss; default gini. |
splitter | {"best", "random"} | Split-selection strategy: best or random; default best. |
max_depth | int or None | Maximum tree depth; None means no explicit depth limit. |
min_samples_split | int or float | Minimum samples required to split an internal node; integer count or fractional proportion. |
min_samples_leaf | int or float | Minimum samples required in a leaf; integer count or fractional proportion. |
min_weight_fraction_leaf | float | Minimum weighted fraction of the total input weight required in a leaf. |
max_features | int, float, {"sqrt", "log2"} or None | Number of features considered for a split, or None for all features. |
random_state | int, RandomState instance or None | Controls estimator randomness. |
max_leaf_nodes | int or None | Maximum number of leaf nodes; None means unlimited. |
min_impurity_decrease | float | Minimum weighted impurity decrease required for a split. |
class_weight | dict, list of dict or "balanced" | Class weights, or None for uniform weighting. |
ccp_alpha | non-negative float | Complexity-pruning parameter; larger values prune more aggressively. |
A fitted DecisionTreeClassifier instance from fit; predict returns class labels and predict_proba returns class probabilities.
from sklearn.tree import DecisionTreeClassifier
X = [[0, 0], [1, 1], [0, 1], [1, 0]]
y = [0, 1, 1, 0]
model = DecisionTreeClassifier(max_depth=2, random_state=0)
model.fit(X, y)
print(model.predict([[0, 0], [1, 1]]))
print(model.predict_proba([[0, 1]]))Creates a bounded-depth classifier, fits it to labeled samples, then predicts classes and class probabilities.
Need an interpretable baseline for labeled tabular data.
Class labels include more than two categories.
Training data contains unequal class frequencies.
Model complexity must be constrained or pruned.
It is a supervised tree model that learns feature-based decision rules for classification. It supports binary and multiclass classification and can return both predicted classes and class probabilities.
Follow-up: How would you reduce overfitting? Limit max_depth, increase min_samples_leaf, restrict max_leaf_nodes, or use cost-complexity pruning with ccp_alpha.
criterion selects the split-quality measure: gini uses Gini impurity, while entropy and log_loss use Shannon information gain. splitter controls whether the best split or a random candidate strategy is used.
Follow-up: When might random splitting help? It can add variation among trees or models, but a fixed random_state is needed for repeatable results.
min_samples_split sets the minimum samples needed to split an internal node, while min_samples_leaf sets the minimum samples permitted in a leaf. Integer values specify counts; float values are fractions converted using a ceiling operation.
Follow-up: Why use min_samples_leaf? It prevents leaves supported by too few observations and can make predictions less sensitive to individual samples.
DecisionTreeRegressorExtraTreeClassifierExtraTreesClassifierRandomForestClassifierHistGradientBoostingClassifiersklearn.tree.plot_tree