Print the actual rules
The one thing a single tree does that nothing else does: give you a decision procedure a human can read and audit line by line.
from sklearn.tree import DecisionTreeClassifier, export_text
tree = DecisionTreeClassifier(
max_depth=3, # constrain it or it memorises the data
min_samples_leaf=100, # no leaf decided by a handful of rows
class_weight="balanced",
random_state=42,
)
tree.fit(X_train, y_train)
print(export_text(tree, feature_names=list(feature_names),
max_depth=3, decimals=1))
# |--- months_delinquent <= 1.5
# | |--- income <= 28500.0
# | | |--- class: 1
# | |--- income > 28500.0
# | | |--- class: 0
# |--- months_delinquent > 1.5
# | |--- class: 1
#
# A shallow tree is often worth fitting purely as documentation, even
# when you deploy a boosted ensemble - it tells you what the dominant
# splits are in language a committee understands.