A decision tree is a flowchart-like predictive model that applies feature-based questions sequentially. Each internal node tests a feature, each branch records an outcome, and each leaf provides the final prediction. section 5.2
A tree visualization exposes how classification decisions are made:
- Decision criteria specify the feature and threshold used to split a node. section 5.2.1
- Gini impurity measures how mixed the class labels are; zero indicates a pure node. section 5.2.1
- Samples counts the observations reaching a node, while value gives the class distribution. section 5.2.1
- The class prediction follows the majority label among observations reaching the node or leaf. section 5.2.1
Classifying cytochrome P450 inhibition
Compute molecular weight and logP descriptors for molecules, then train a depth-2 decision tree classifier. During inference, a molecule first answers a root question such as whether logP is at most 2.294, continues through additional thresholds, and ends with a predicted class and probability estimate. section 5.2.1
Listing 5.3 Train Decision Tree Classifier
from rdkit.Chem import Descriptors
from sklearn.tree import DecisionTreeClassifier, export_graphviz, plot_tree
RDKIT_DESCRIPTORS = {
'MolWt' : Descriptors.MolWt,
'logP' : Descriptors.MolLogP,
}
for desc, func in RDKIT_DESCRIPTORS.items():
train_df[desc] = train_df["Molecule"].apply(func)
val_df[desc] = val_df["Molecule"].apply(func)
tree_clf = DecisionTreeClassifier(max_depth=2)
tree_clf.fit(train_df[['MolWt', 'logP']], train_df.Inhibitor)
val_df['Predicted Class'] = tree_clf.predict(val_df[['MolWt', 'logP']])
val_df['Probability Estimate'] = tree_clf.predict_proba(
val_df[['MolWt', 'logP']]
)[:,1] Runnable code derives RDKit molecular descriptors, fits a scikit-learn decision tree, and produces validation predictions and probability estimates. section 5.2.1
Deep trees can achieve low bias but have high variance: small training-set changes may substantially alter their structure. Regularize with limits such as max_depth, max_features, max_leaf_nodes, min_samples_split, min_samples_leaf, or min_impurity_decrease; pruning removes unsupported splits after construction. section 5.3.1

















