Skip to content

sklearn Transformers

molfp.sklearn

scikit-learn compatible transformer for all fingerprint types.

A single FingerprintTransformer wraps any fingerprint registered in FINGERPRINTS, making all 40+ types usable in sklearn Pipelines, GridSearchCV, cross_val_score, etc.

Usage

import molfp

Basic

t = molfp.FingerprintTransformer("ecfp4") X = t.fit_transform(smiles)

With custom bit size

t = molfp.FingerprintTransformer("ecfp4", n_bits=2048)

In a Pipeline with GridSearchCV over fp_type

from sklearn.pipeline import Pipeline from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import GridSearchCV

pipe = Pipeline([ ("fp", molfp.FingerprintTransformer("ecfp4")), ("clf", RandomForestClassifier()), ]) search = GridSearchCV(pipe, { "fp__fp_type": ["ecfp4", "rdk", "maccs", "map4"], "fp__n_bits": [512, 1024, 2048], }, cv=5) search.fit(smiles, y)

FingerprintTransformer

Bases: BaseEstimator, TransformerMixin

Universal sklearn transformer for any molfp fingerprint.

Parameters

fp_type : str Fingerprint name (must exist in molfp.FINGERPRINTS). n_bits : int or None Bit size override. Ignored for fixed-size fingerprints (e.g. maccs). When None, uses the default from the FINGERPRINTS registry. n_jobs : int Number of parallel workers (passed to joblib). -1 uses all cores. sparse : bool If True, return a scipy sparse matrix instead of a dense array.

get_transformer(name, **kwargs)

Get a sklearn transformer by fingerprint name.

Example: molfp.get_transformer("ecfp4", n_bits=2048, n_jobs=-1)