liveBook · Manning

Principal component

As explained in Build AI Drug Discovery Pipelines

A principal component is a transformed feature formed as a linear combination of original features that captures a successive amount of data variance.

A principal component is a new feature formed by combining original features. PCA orders these features by the amount of data variance they explain, allowing a high-dimensional data set to be represented with fewer dimensions. section 1.2.3 section 6.2.3

PCA creates orthogonal axes in a new coordinate system. Retaining the first k components preserves the largest available variation while reducing the computational and visualization burden. section 6.2.3

A practical molecular workflow is:

  • Represent molecules with high-dimensional fingerprints, such as 1024-bit ECFP6 features. section 1.2.3
  • Fit PCA and transform the feature matrix into a smaller representation, such as four principal components. section 1.2.3 section 6.2.3
  • Inspect component cross-sections to explore chemical space or provide inputs for a classifier. section 1.2.3

FDA-approved drug chemical space

A data set of FDA-approved molecules is converted from SMILES into RDKit molecules, encoded as 1024-dimensional Morgan fingerprints, and reduced to four components with sklearn PCA. Cross-sections reveal distinct regions for several USAN stem classes, including “-caine,” “-cillin,” “-pine,” and “-sulfa”; the resulting components can also support logistic-regression decision boundaries. section 1.2.3

Listing 1.2 Example Applications with USAN Stems
from rdkit.Chem.rdFingerprintGenerator import GetMorganGenerator
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression
 
fda_approved_df = pd.read_csv(
    'data/fda_approved_drugs/fda_approved_drugs.csv', sep=','
)
PandasTools.AddMoleculeColumnToFrame(
    fda_approved_df, smilesCol='Smiles', molCol='ROMol'
)
fda_approved_df = fda_approved_df[~fda_approved_df['ROMol'].isnull()]
morgan_gen = GetMorganGenerator(radius=3, fpSize=1024)
fda_approved_df['ECFP6'] = fda_approved_df['ROMol'].apply(
    lambda mol: morgan_gen.GetFingerprint(mol)
)
 
X = np.array([x for x in fda_approved_df['ECFP6']])
pca = PCA(n_components=4, random_state=42)
pca_drugs = pca.fit_transform(X)
fda_approved_df['PC1'] = pca_drugs.T[0]
fda_approved_df['PC2'] = pca_drugs.T[1]
fda_approved_df['PC3'] = pca_drugs.T[2]
fda_approved_df['PC4'] = pca_drugs.T[3]
 
sns.pairplot(
    fda_approved_df,
    hue='USAN Stem',
    vars=['PC1', 'PC2', 'PC3', 'PC4'],
    palette='viridis'
)
 
fda_approved_df['cillin'] = (
    fda_approved_df['USAN Stem'] == '-cillin'
).astype(int)
fda_approved_df['olol'] = (
    fda_approved_df['USAN Stem'] == '-olol'
).astype(int)
 
lr_model_cillin = LogisticRegression()
lr_model_cillin.fit(fda_approved_df[['PC1', 'PC3']], fda_approved_df.cillin)
 
xx = np.mgrid[fda_approved_df.PC1.min():fda_approved_df.PC1.max():.01
yy = fda_approved_df.PC3.min():fda_approved_df.PC3.max():.01]
grid = np.c_[xx.ravel(), yy.ravel()]
probs = lr_model_cillin.predict_proba(grid)[:, 1].reshape(xx.shape)
 

Runnable code shows RDKit molecular conversion, Morgan fingerprint generation, sklearn PCA fitting, and assignment of PC1–PC4 coordinates. section 1.2.3

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains component construction, orthogonal axes, variance ordering, projection, and retaining k components, without deriving PCA mathematically.
Examples
Uses FDA-approved drug fingerprints, USAN stem regions, two-dimensional component cross-sections, and a four-component PCA implementation.
What it assumes
Assumes a feature matrix and introduces the intuition that some dimensions carry more useful variation than others.
What you can do after
Apply it via sklearn PCA to reduce molecular fingerprints and visualize or model patterns in chemical space.
How it connects
Connects dimensionality reduction with variance, chemical space, molecular fingerprints, logistic regression, and representative data splitting.

Also explained in

Compare how 6 books explain principal component →

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.