Gini impurity measures how often a randomly labeled sample would be misclassified within a decision-tree node. A value of 0 means every molecule belongs to one class; higher values indicate mixed labels. section 5.2.1
Use the node’s class distribution to interpret the metric:
- Binary classification reaches its maximum, 0.5, when the node is split evenly between classes. section 5.2.1
- Decision trees favor splits that reduce impurity, weighting each child by the number of samples it receives. section 5.2.1
- Inspect samples, class counts, and predicted class alongside Gini to understand each node’s decision. section 5.2.1
Cytochrome P450 inhibition
A decision tree trained on molecular weight and logP can split molecules into inhibitor and noninhibitor groups. Its root contains 5,151 noninhibitors and 3,478 inhibitors, so the node is impure; later splits may create purer groups. 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] Run the compact Python workflow to calculate RDKit descriptors, train a depth-two classifier, and obtain predictions and probability estimates. section 5.2.1








