liveBook · Manning

Covariate shift

As explained in Build AI Drug Discovery Pipelines

Covariate shift is a distribution shift in which the input-feature distribution changes between training and deployment while the conditional target relationship remains unchanged.

Covariate shift occurs when feature distributions change between training and deployment while the true relationship between features and the target remains unchanged. This can reduce reliability when inference data occupies unfamiliar chemical space. section 4.1.3

Molecular-weight distribution shift

Suppose a solubility model trains only on molecules below 500 daltons, then encounters more molecules above 500 daltons during inference. Molecular-weight distributions differ, but the relationship between molecular weight and solubility has not fundamentally changed; predictions may still generalize poorly because deployment moves beyond the training distribution. section 4.1.3

Listing 4.3 Compute RDKit Descriptors
from rdkit.Chem import (
    Crippen,
    Descriptors,
    GraphDescriptors,
    Lipinski,
    MolFromSmarts,
    rdMolDescriptors,
)
 
def AromaticProportion(mol):
  if mol is None or mol.GetNumAtoms() == 0:    #A
    return 0.0    #A
  aromatic_atoms = mol.GetSubstructMatches(
      MolFromSmarts("a")
  )
  return len(aromatic_atoms) / mol.GetNumAtoms()
 
RDKIT_DESCRIPTORS = {
  'Molecular Weight' : Descriptors.MolWt,
  'Number of H-Bond Donors' : Descriptors.NumHDonors,
  'TPSA' : Descriptors.TPSA,
  'logP' : Crippen.MolLogP,
  'Molar Refractivity' : Crippen.MolMR,
  'Number of Rotatable Bonds' : Lipinski.NumRotatableBonds,
  'Number of Rings' : rdMolDescriptors.CalcNumRings,
  'LabuteASA' : rdMolDescriptors.CalcLabuteASA,
  'BalabanJ' : GraphDescriptors.BalabanJ,
  'BertzCT' : GraphDescriptors.BertzCT,
  'Aromatic Proportion' : AromaticProportion,
}
 
for desc, func in RDKIT_DESCRIPTORS.items():
  train_df[desc] = train_df["Molecule"].apply(func)

Inspect the RDKit descriptors that define molecular feature distributions, including molecular weight, hydrogen-bond donors, TPSA, logP, rings, and aromatic proportion. section 4.1.3

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines feature-distribution shift, preserves the target relationship, and illustrates the idea with molecular weight and solubility.
Examples
Uses solubility prediction with training molecules below 500 daltons and inference molecules increasingly above that threshold.
What you can do after
Evaluate whether deployment molecules fall outside the feature range represented by training data.
How it connects
Connects applicability domain with interpolation and extrapolation when judging reliability across chemical space.

Also explained in

Compare how 2 books explain covariate shift →

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.