butina_train_test_split#
- skfp.model_selection.butina_train_test_split(data: Sequence[str | Mol], *additional_data: Sequence, train_size: float | None = None, test_size: float | None = None, threshold: float = 0.65, return_indices: bool = False) tuple[Sequence[str | Mol], Sequence[str | Mol], Sequence[Sequence[Any]]] | tuple[Sequence, ...] | tuple[Sequence[int], Sequence[int]]#
Split using Taylor-Butina clustering.
This split uses deterministically partitioned clusters of molecules from Taylor-Butina clustering [1] [2] [3]. It aims to verify the model generalization to structurally novel molecules. Also known as sphere exclusion or leader-following clustering.
First, molecules are vectorized using binary ECFP4 fingerprint (radius 2) with 2048 bits. They are then clustered using Leader Clustering, a variant of Taylor-Butina clustering by Roger Sayle [4] for RDKit. Cluster centroids (central molecules) are guaranteed to have at least a given Tanimoto distance between them, as defined by threshold parameter.
Clusters are divided deterministically, with the smallest clusters assigned to the test subset and the rest to the training subset.
If
train_sizeandtest_sizeare integers, they must sum up to thedatalength. If they are floating numbers, they must sum up to 1.- Parameters:
data (sequence) – A sequence representing either SMILES strings or RDKit
Molobjects.additional_data (list[sequence]) – Additional sequences to be split alongside the main data (e.g., labels or feature vectors).
train_size (float, default=None) – The fraction of data to be used for the train subset. If None, it is set to 1 - test_size. If test_size is also None, it will be set to 0.8.
test_size (float, default=None) – The fraction of data to be used for the test subset. If None, it is set to 1 - train_size. If train_size is also None, it will be set to 0.2.
threshold (float, default=0.65) – Tanimoto distance threshold, defining the minimal distance between cluster centroids. Default value is based on ECFP4 activity threshold as determined by Roger Sayle [4].
return_indices (bool, default=False) – Whether the method should return the input object subsets, i.e. SMILES strings or RDKit
Molobjects, or only the indices of the subsets instead of the data.
- Returns:
subsets – Tuple with train-test subsets of provided arrays. First two are lists of SMILES strings or RDKit
Molobjects, depending on the input type. If return_indices is True, lists of indices are returned instead of actual data.- Return type:
tuple[list, list, …]
References
Examples
>>> from skfp.model_selection.splitters import butina_train_test_split >>> smiles = ['c1ccccc1', 'c1cccnc1', 'c1ccncc1', 'CC(=O)O', 'CC(N)=O', 'CCCCCC', 'CCCCCN', 'c1ccc(O)cc1'] >>> train_smiles, test_smiles = butina_train_test_split(smiles, train_size=0.75, test_size=0.25) >>> train_smiles ['CCCCCN', 'CCCCCC', 'CC(N)=O', 'CC(=O)O', 'c1ccncc1', 'c1cccnc1']