CART (Classification and Regression Trees) builds a binary decision tree by repeatedly choosing a feature and threshold that produce the purest child nodes. In molecular-property classification, this can separate cytochrome P450 inhibitors from noninhibitors using descriptors such as molecular weight and logP. Splitting continues until limits such as maximum depth, minimum node size, or pure leaves stop the process. section 5.2.1
A CART classification workflow:
- Evaluate candidate feature thresholds and select the split with the greatest weighted purity gain. section 5.2.1
- Measure node impurity with Gini impurity; zero means every training instance has the same class. section 5.2.1
- Assign each leaf a predicted class, and optionally estimate class probability from the fitted tree. 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] Train a depth-two scikit-learn tree from RDKit molecular-weight and logP descriptors, then predict validation classes and inhibitor probabilities. section 5.2.1


