A Chemically Biased Parametric Data Splitting Method
The Analogue Split method is designed to analyze and improve the robustness of machine learning models by considering activity cliffs in molecular datasets. Activity cliffs are pairs of similar molecules with significantly different biological activities, which can challenge the performance of predictive models.
This package provides tools to:
- Ensure a specified fraction of the test set molecules are involved in activity cliffs.
- Analyze model performance as a function of the proportion of activity cliffs in the test set.
- Visualize these analyses through gamma plots.
You can install the package from PyPI using:
pip install analoguesplit
- gamma: Fraction of the test set comprising of activity cliffs.
- omega: Similarity threshold to create edges between molecules.
- test_size: Fraction of the dataset to be used as the test set.
- X: Feature vector (molecular fingerprints).
- y: Label vector (biological activities).
Sets a random seed for reproducibility.
def set_random_seed(seed: int) -> None:
Calculates molecular fingerprints for a list of molecules.
def calculate_fp(mols: list[Chem.rdchem.Mol], fp: str = "ecfp4") -> np.ndarray:
Converts a list of SMILES strings to RDKit molecule objects.
def convert_smiles_to_mol(smis: list[str]) -> list[Chem.rdchem.Mol]:
Calculates the similarity matrix for molecular fingerprints using a specified similarity function.
def calculate_simmat(fps: np.ndarray, similarity_function) -> np.ndarray:
Calculates the Tanimoto similarity coefficient between two binary vectors.
def tanimoto_similarity(fp1: np.ndarray, fp2: np.ndarray) -> float:
Identifies activity cliffs in the dataset.
def find_activity_cliffs(fps: np.ndarray, labels: np.ndarray, threshold: float) -> list[tuple[int, int]]:
Splits the dataset into training and test sets, ensuring a specified fraction of the test set molecules are activity cliffs.
def analogue_split(fps: np.ndarray, labels: np.ndarray, test_size: float, gamma: float, omega: float) -> tuple[np.ndarray, np.ndarray]:
Trains and evaluates models using the analogue split and returns evaluation results.
def train_and_evaluate_models(gammas: list[float], fps: np.ndarray, labels: np.ndarray, models: dict, test_size: float, omega: float) -> dict:
Plots evaluation results for different gamma values.
def plot_evaluation_results(results: dict, gammas: list[float], title: str) -> None:
- Identify Activity Cliff Molecules: Determine which molecules are part of activity cliffs based on their similarity and class labels.
- Generate Test Sets: For each gamma value, create test sets with the desired proportion of activity cliff molecules.
- Evaluate Model Performance: Train models on the training set and evaluate them on the test sets, calculating metrics such as accuracy, precision, recall, and F1 score.
- Create Gamma Plot: Visualize the model performance metrics against gamma values to understand the impact of activity cliffs on model robustness.
Please check Notebook to learn how to use analoguesplit
.
This project is licensed under the MIT License.
This package relies on several excellent Python libraries including RDKit, scikit-learn, NumPy, and Matplotlib.