MolBasis
kernel-fittingscaffold-splitridgeexponent-gridscikit-learn6 min read

Building your own property kernel on your own data

Split by scaffold first, search descriptor and exponent on the training part only, fit ridge on z-scored terms, then report held-out r, lift and slope.

Updated November 28, 2026

Building a kernel on your own data follows the MolBasis protocol in six steps. Deduplicate by molecule, compute the nine descriptors with one mfsig recipe throughout, hold out 25 percent of Bemis-Murcko scaffolds before any fitting, search descriptor and exponent on the training part only, refit ridge on z-scored terms, then measure Pearson r, MAE lift and calibration slope on the held-out part once. Because MolBasis does not publish coefficients, this is also the only route to a kernel you can evaluate on new molecules. This guide gives the procedure with a scikit-learn snippet and names the checks that turn a fit into a result.

Assemble and clean the data first

Start from a table with a SMILES string, a target value and its unit, and a source. Canonicalise the SMILES with RDKit and compute the InChIKey. Merge rows that share the first block of the InChIKey, since those are the same connectivity, and decide in writing how conflicting measurements are merged, by median, by most recent, or by dropping. Convert every target to one unit, log units for solubility and partition, kcal/mol for solvation energies, kelvin or celsius for melting point, stated once. Record the row count before and after. Each of these decisions changes the training mean and therefore the intercept, so each belongs in the manifest.

Compute descriptors with one recipe throughout

Run every molecule through mfsig at one version. The current recipe v1.0.0 writes ångström units from MMFF94s geometries. Older v0.91.1 files, the ones the MolBasis kernels used, hold bohr² areas and UFF geometries. Mixing the two in one dataset puts molecules on two different scales and ruins the fit. Pull the nine descriptors into a matrix with one row per molecule and nine columns in a fixed order, as shown in from an mfsig file to a descriptor vector, and store the version in the manifest. Remember that hb_donor_mass is zero in v0.91.1 production files, so with those files you have eight usable columns.

Split by scaffold before you look at anything

Compute the Bemis-Murcko scaffold of each molecule. Collect the unique scaffolds, shuffle them with a fixed seed, and assign 25 percent of the scaffolds to the held-out set. Every molecule inherits its scaffold's side. Store both lists. The guide on the scaffold split with Bemis-Murcko scaffolds has the RDKit code. Do this before computing a single correlation. The held-out set does not exist for the rest of the procedure until the final measurement.

Note what the share means. Twenty-five percent of scaffolds can be far fewer than 25 percent of molecules when a few scaffolds dominate. Check the held-out count. If it is a handful, say so when you report, and run more seeds.

Search on the training part only

The search tries every descriptor against every exponent on the grid, z-scores the transformed column with training statistics, fits ridge, and scores the fit. The record used a grid step of 0.25. The range is your choice and must be stated. The snippet ranks by in-training r, which is the simplest criterion and the most optimistic. A grouped cross-validation score inside the training set is better, and the guide on power-law terms and exponent grids explains why the grid itself is a source of optimism.

import numpy as np
from sklearn.linear_model import Ridge

GRID = np.arange(0.25, 3.01, 0.25)      # step 0.25, range is your choice

def search_one_term(F_tr, y_tr, names):
    """F_tr: (n, 9) training descriptors. Columns must be positive before
    a fractional power, so shift or exclude negative columns and say how."""
    results = []
    for j, name in enumerate(names):
        col = F_tr[:, j]
        if np.any(col <= 0):
            continue                      # state this exclusion in the report
        for p in GRID:
            t = col ** p
            mu, sd = t.mean(), t.std(ddof=0)
            z = ((t - mu) / sd).reshape(-1, 1)
            m = Ridge(alpha=1e-3).fit(z, y_tr)
            r = np.corrcoef(m.predict(z), y_tr)[0, 1]
            results.append((r, name, p, mu, sd, m.intercept_, m.coef_[0]))
    results.sort(key=lambda row: -row[0])
    return results                        # keep the whole list, not only row 0

Keep the whole sorted list. The equations within 0.01 r of the top one form the plateau, and reporting its size tells the reader how arbitrary the winner is. Skipping negative columns is one way to handle fractional powers. Shifting them is another. Either must be stated, because it changes which descriptor can win.

Refit, then measure once on the held-out part

Take the winning descriptor and exponent. Refit β on the whole training part with the training mean and sd fixed. Then, for the first time, transform the held-out molecules with those same training constants and compute three numbers. Pearson r between prediction and observation. MAE lift, which is one minus the model MAE over the MAE of predicting the training mean for every held-out molecule. Calibration slope, observed regressed on predicted. The MolBasis gate calls a kernel A.IMPROVE when the lift reaches 30 percent. Do not go back and change the exponent after seeing these numbers. If you do, the held-out set has become a second training set and you need a third.

Add the gate checks, and one the record lacks

The MolBasis rigor gate adds grouped leave-one-out by molecule, bootstrap intervals on r and MAE, a permutation floor, nested cross-validation, a plateau count, a calibration slope and a feature-addition test. The permutation floor is the one to add first. Shuffle the target, rerun the whole search, record the best r, repeat a few hundred times, and require your real winner to sit at least 0.30 r above the 95th percentile of that noise. The guide on permutation tests and y-scrambling explains why a search over nine descriptors and a dozen exponents finds a decent r in pure noise more often than intuition expects.

The check the record lacks is repetition over seeds. The site states one split, one seed, no confidence interval. Run the whole procedure over ten or twenty seeds and report the median and range of held-out r. It costs minutes and converts a figure into a distribution. Then write down everything, following the methodology page as a template for what a protocol statement should contain, and keep the per-molecule held-out predictions, because they let anyone recompute what you report.

Key points

  • Deduplicate by InChIKey first block, unify units, and record every merging decision, because each changes the intercept.
  • One mfsig recipe for all molecules. Current files are self-consistent but not comparable with v0.91.1 fits.
  • Hold out 25 percent of scaffolds before any correlation is computed, and check how many molecules that leaves.
  • Search on the training part only, keep the whole ranked list, state how negative columns were handled, and measure the held-out set once.
  • Add the permutation floor and repeat over seeds. Those two checks turn a lucky figure into a result.

Questions people ask

What is the minimum procedure for fitting a one-term kernel honestly?
Deduplicate by molecule, hold out 25 percent of Bemis-Murcko scaffolds before looking at any descriptor, search descriptor and exponent on the training part only, z-score with training constants, fit ridge with a small λ, then compute Pearson r, MAE lift over the training mean and calibration slope on the held-out part once.
Why not pick the exponent on the whole dataset and then split?
Because the selection is part of the model. An exponent chosen on all the data has seen the test molecules, and the held-out figure then includes the optimism of the search. Three MolBasis equations were corrected for this reason, from two-term full-data fits to one-term held-out fits.
Should I use current mfsig files or the v0.91.1 recipe?
Use one recipe for every molecule in your dataset and record which. Current mfsig files use ångström units and MMFF94s geometries. Your fit will be self-consistent on them. It will not be comparable with a kernel fitted on v0.91.1 files, and you should not expect the same descriptor or exponent to win.
How many seeds should I run?
More than one. The MolBasis record used one seed, and the site says so. Repeating the scaffold split over ten or more seeds and reporting the spread of held-out r is the cheapest improvement on that protocol.

Further reading

In practice: The coefficients of the kernels are not published, so no kernel can be evaluated from this site alone, and no figure here was recomputed except the separate blind benchmark. The guides say what can be done with what is available.

See the kernels themselves

Every kernel is shown with its held-out result, the number of molecules it rests on and what it cannot be trusted for.