liveBook · Manning

Decision tree

As explained in Build AI Drug Discovery Pipelines

A decision tree is a hierarchical predictive model that applies feature-based decision rules to reach an output.

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

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains nodes, impurity, traversal, predictions, probability estimates, regularization, and pruning.
Examples
Demonstrates molecular weight and logP descriptors, a depth-2 classifier, tree visualizations, and five-molecule validation traversal.
What it assumes
Assumes feature-based classification while defining node structure, impurity, samples, values, and majority-vote predictions.
What you can do after
Build it with RDKit and scikit-learn, visualize decisions, and generate class predictions and probability estimates.
How it connects
Connects feature descriptors, Gini impurity, validation sets, bias-variance trade-offs, regularization, pruning, and random forests.

Also explained in

Compare how 18 books explain decision tree →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.