### Import Libraries and Setup Autoreload for splito Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Initial setup for the `splito` project, including loading autoreload extensions for development, importing `datamol` for data handling, `SIMPDSplitter` from `splito.simpd` for the core splitting functionality, and a utility for chemical space visualization. ```python %load_ext autoreload %autoreload 2 import datamol as dm from splito.simpd import SIMPDSplitter from utils import visualize_chemspace ``` -------------------------------- ### Build and serve Splito documentation Source: https://github.com/datamol-io/splito/blob/main/README.md Builds the project documentation and starts a local server for preview using mkdocs, allowing developers to review changes. ```bash mkdocs serve ``` -------------------------------- ### Set up Splito development environment Source: https://github.com/datamol-io/splito/blob/main/README.md Initializes a dedicated micromamba environment for Splito development, activates it, and installs the project in editable mode without dependencies. ```bash micromamba create -n splito -f env.yml micromamba activate splito pip install --no-deps -e . ``` -------------------------------- ### Install Splito using pip Source: https://github.com/datamol-io/splito/blob/main/docs/index.md Installs the `splito` library and its dependencies using the pip package manager, a common method for Python package installation. ```bash pip install splito ``` -------------------------------- ### Load example molecular dataset using datamol Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb This code loads the `freesolv` dataset, a common benchmark in cheminformatics, using the `datamol` library. This dataset will be used as input for the `LoSplitter`. ```python data = dm.data.freesolv() data ``` -------------------------------- ### Install Splito with pip Source: https://github.com/datamol-io/splito/blob/main/README.md Installs the Splito library using the pip package manager, a common method for Python package installation. ```bash pip install splito ``` -------------------------------- ### Install Splito using mamba or conda Source: https://github.com/datamol-io/splito/blob/main/docs/index.md Installs the `splito` library using mamba or conda from the conda-forge channel. This method might require specific credentials or a token for access. ```bash mamba install -c conda-forge splito ``` -------------------------------- ### Install Splito with mamba Source: https://github.com/datamol-io/splito/blob/main/README.md Installs the Splito library using the mamba package manager from the conda-forge channel, suitable for Conda environments. ```bash mamba install -c conda-forge splito ``` -------------------------------- ### Configure SIMPD Objectives and Constraints for Data Splitting Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Sets various parameters related to SIMPD objectives and constraints for the multi-objective genetic algorithm. These parameters guide the optimization process to achieve desired characteristics in the generated train/test splits, such as active fraction targets and descriptor differences. ```python args["simpd_descriptors"] = None args["target_train_frac_active"] = -1 args["target_test_frac_active"] = -1 args["target_delta_test_frac_active"] = None # [0.11, 0.30] or None args["target_GF_delta_window"] = (10, 30) args["target_G_val"] = 70 args["max_population_cluster_entropy"] = 0.9 args["pareto_weight_GF_delta"] = 10 args["pareto_weight_G"] = 5 ``` -------------------------------- ### Configure splito for advanced filter exclusions Source: https://github.com/datamol-io/splito/blob/main/docs/api/splito.md This YAML configuration showcases advanced filter control in `splito`. It defines a set of filters to be explicitly excluded, specifically any filter starting with an underscore (`_`) and the `train_test_split` filter, providing fine-grained control over data processing. ```YAML options: filters: ["!^_", "!train_test_split"] ``` -------------------------------- ### Initialize Python Environment and Import Libraries for Splito Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This snippet sets up the Python environment by loading autoreload extensions and imports necessary libraries such as `datamol` for cheminformatics operations, `splito` for dataset splitting, and a custom `visualize_chemspace` utility. ```python %load_ext autoreload %autoreload 2 import datamol as dm import splito from utils import visualize_chemspace ``` -------------------------------- ### Initialize Python Environment and Import Libraries Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Structure_based_Splitters.ipynb This snippet prepares the Python environment by loading the autoreload extension, which automatically reloads modules. It then imports essential libraries: `datamol` for data handling, `splito` for advanced splitting, and `visualize_chemspace` from a local `utils` module for analysis. ```python %load_ext autoreload %autoreload 2 import datamol as dm import splito from utils import visualize_chemspace ``` -------------------------------- ### Initialize `splito` Environment and Libraries Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/The_Basics.ipynb Sets up the IPython environment for autoreload and imports necessary libraries: `datamol` for data manipulation, `splito` for data splitting, and `visualize_chemspace` from a local utility. ```python %load_ext autoreload %autoreload 2 import datamol as dm import splito from utils import visualize_chemspace ``` -------------------------------- ### Load Sample Chemical Dataset with Datamol Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Structure_based_Splitters.ipynb This code demonstrates how to load a pre-built dataset, specifically the 'freesolv' dataset, using the `datamol` library. After loading, it displays the first 10 rows of the dataset to provide a quick overview of its structure and content. ```python # Load dataset data = dm.data.freesolv() data.head(10) ``` -------------------------------- ### Load Sample Solubility Dataset using datamol Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Loads a sample solubility dataset using `datamol.data.solubility()` for demonstration purposes. The `head(5)` call displays the first five rows of the loaded DataFrame. ```python # load dataset data = dm.data.solubility() data.head(5) ``` -------------------------------- ### Instantiate and Fit SIMPDSplitter with Dataset Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Initializes an instance of `SIMPDSplitter` using the previously defined `args` dictionary. It then fits the splitter to the molecular data and classification data, initiating the multi-objective genetic algorithm to find optimal data splits. ```python simpd_splitter = SIMPDSplitter(**args) result = simpd_splitter.fit(data[mol_col].values, data[data_col].values) ``` -------------------------------- ### Import necessary libraries for Lo Splitter Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb Imports `datamol`, `splito.lohi.LoSplitter`, `rdkit.Chem`, `rdkit.Chem.Draw`, `numpy`, and `scipy.stats.spearmanr` for data handling, splitting, visualization, numerical operations, and statistical analysis. ```python import datamol as dm from splito.lohi import LoSplitter from rdkit import Chem from rdkit.Chem import Draw import numpy as np from scipy.stats import spearmanr ``` -------------------------------- ### Load Dataset and Configure Scaffold Splitter Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/The_Basics.ipynb Loads a sample chemical dataset using `datamol.data.chembl_drugs()`. It then initializes a `splito.ScaffoldSplit` object, configuring it with the SMILES strings from the dataset, parallel processing (`n_jobs=-1`), a specified test set size (`0.2`), and a random state for reproducibility. ```python data = dm.data.chembl_drugs() ``` ```python splitter = splito.ScaffoldSplit(smiles=data.smiles.tolist(), n_jobs=-1, test_size=0.2, random_state=111) ``` -------------------------------- ### Initialize Basic SIMPDSplitter Parameters Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Initializes an empty dictionary `args` and sets the `n_splits` parameter to 5. This parameter defines the number of splits to generate for the dataset using the `SIMPDSplitter`. ```python args = {} args["n_splits"] = 5 ``` -------------------------------- ### Untitled Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb No description -------------------------------- ### Load toy dataset using datamol Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb Loads the 'freesolv' toy dataset using `datamol.data.freesolv()` for demonstration purposes. This dataset contains molecular information, including SMILES strings and calculated properties. ```python data = dm.data.freesolv() data ``` -------------------------------- ### Initialize and use Splito's ScaffoldSplit for dataset splitting Source: https://github.com/datamol-io/splito/blob/main/docs/index.md Demonstrates how to load chemical data using `datamol`, initialize the `ScaffoldSplit` class with SMILES strings, and generate training and testing dataset indices based on a scaffold split strategy. ```python import datamol as dm from splito import ScaffoldSplit # Load some data data = dm.data.chembl_drugs() # Initialize a splitter splitter = ScaffoldSplit(smiles=data["smiles"].tolist(), n_jobs=-1, test_size=0.2, random_state=111) # Generate indices for training set and test set train_idx, test_idx = next(splitter.split(X=data.smiles.values)) ``` -------------------------------- ### Import necessary libraries for LoSplitter Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb This snippet imports the required Python libraries, including `datamol` for data handling, `LoSplitter` from `splito.lohi` for the core splitting functionality, `rdkit.Chem` for cheminformatics operations, and `numpy`/`scipy` for numerical computations. ```python import datamol as dm from splito.lohi import LoSplitter from rdkit import Chem from rdkit.Chem import Draw import numpy as np from scipy.stats import spearmanr ``` -------------------------------- ### Fitting MOODSplitter to Rank Splitting Methods Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MOOD_Protocol.ipynb This code demonstrates how to fit the `MOODSplitter` instance. It takes the featurized training dataset (`dataset_feat`) and the featurized deployment dataset (`deployment_feat`) as input. The `fit` method then evaluates and ranks the defined splitting methods based on their ability to mimic the deployment distribution. ```python # get the rank of the splitting methods with the givent deployment set splitter.fit(X=np.stack(dataset_feat), X_deployment=np.stack(deployment_feat)) ``` -------------------------------- ### Importing Libraries for Molecular Splitting Analysis Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MOOD_Protocol.ipynb This snippet imports necessary libraries for molecular splitting analysis, including `numpy` for numerical operations, `datamol` for cheminformatics utilities, `sklearn.model_selection.ShuffleSplit` for random splitting, and `splito` for specialized molecular splitting methods. It also loads autoreload extensions for development. ```python %load_ext autoreload %autoreload 2 import numpy as np import datamol as dm from sklearn.model_selection import ShuffleSplit import splito ``` -------------------------------- ### Define placeholder functions for model training and prediction Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb Provides `train_model` and `predict` functions as illustrative placeholders. These functions demonstrate where a user would integrate their actual machine learning model training logic (e.g., using `train_data`) and inference logic (e.g., generating `predictions` for `test_data`). ```python def train_model(train_data): # add your model training here model = None return model def predict(model, test_data): # add your code here predictions = np.random.normal(size=len(test_data)) return predictions ``` -------------------------------- ### Set Genetic Algorithm Parameters for SIMPDSplitter Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Configures the genetic algorithm parameters within the `args` dictionary. `pop_size` sets the population size to 500, and `ngens` defines the number of generations to run the algorithm for, set to 10. ```python args["pop_size"] = 500 args["ngens"] = 10 ``` -------------------------------- ### Initialize LoSplitter and split data Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb Instantiates the `LoSplitter` and applies it to split the 'smiles' (molecular structures) and 'calc' (calculated properties) columns of the loaded dataset. It returns `train_idx` (indices for the training set) and `cluster_idx` (a list of lists, where each inner list contains indices of molecules in a test cluster). ```python lo_splitter = LoSplitter() train_idx, cluster_idx = lo_splitter.split(data['smiles'], data['calc']) ``` -------------------------------- ### Loading Molecular Datasets for Splitting Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MOOD_Protocol.ipynb This code loads a training dataset (solubility data) and a deployment dataset (ChEMBL drugs) using `datamol`. It then converts the molecular structures into molecular fingerprints (`dm.to_fp`) for feature representation, which are used in the splitting process. ```python # Load the training dataset dataset = dm.data.solubility() dataset_feat = [dm.to_fp(mol) for mol in dataset.mol] # Load the deployment set # Alternatively, you can also load an array of deployment-to-dataset distance deployment_feat = [dm.to_fp(mol) for mol in dm.data.chembl_drugs()["smiles"]] ``` -------------------------------- ### Visualize another molecular cluster from Lo Splitter Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb Similar to the previous snippet, this code visualizes the fourth cluster from `cluster_idx`. It extracts SMILES, converts to RDKit molecules, and displays them as a grid image, further illustrating the composition of the Lo Splitter's generated clusters. ```python # Visualize another cluster cluster_smiles = data.iloc[cluster_idx[3]]['smiles'] molecules = [Chem.MolFromSmiles(smiles) for smiles in cluster_smiles] img = Draw.MolsToGridImage(molecules, molsPerRow=5, subImgSize=(300, 300)) img ``` -------------------------------- ### Format Splito code with ruff Source: https://github.com/datamol-io/splito/blob/main/README.md Automatically formats the Splito codebase according to predefined style rules using ruff, ensuring consistent code formatting. ```bash ruff format ``` -------------------------------- ### Apply StratifiedDistributionSplit to Partition Dataset by Readout Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This code demonstrates the use of `splito.StratifiedDistributionSplit` to create train and test sets with similar distributions of a target readout. It initializes the splitter and then applies it, using both SMILES and experimental values (`expt`) to ensure stratification, finally labeling the DataFrame. ```python splitter = splito.StratifiedDistributionSplit(test_size=0.2, random_state=111) train_idx, test_idx = next(splitter.split(X=data["smiles"].tolist(), y=data.expt.tolist())) assert train_idx.shape[0] > test_idx.shape[0] data.loc[train_idx, "StratifiedDistributionSplit"] = "train" data.loc[test_idx, "StratifiedDistributionSplit"] = "test" ``` -------------------------------- ### Visualize Train/Test Splits in Chemical Space Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Structure_based_Splitters.ipynb This snippet utilizes a helper function, `visualize_chemspace`, to graphically represent the distributions of the train and test sets. It takes the main dataframe and a list of split names (PerimeterSplit and MaxDissimilaritySplit) to show how each method partitions the data within the chemical space, aiding in visual analysis of the splitting effectiveness. ```python visualize_chemspace(data, split_names=["PerimeterSplit", "MaxDissimilaritySplit"]) ``` -------------------------------- ### Set Miscellaneous SIMPDSplitter Execution Parameters Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Defines additional execution parameters for `SIMPDSplitter`, including the number of threads for parallel processing, a random seed for reproducibility, and various verbosity and progress display options for monitoring the algorithm's execution. ```python args["num_threads"] = 4 args["random_seed"] = 111 args["verbose"] = True args["verbose_pymoo"] = True args["progress"] = True args["progress_leave"] = True ``` -------------------------------- ### Visualize a molecular cluster from Lo Splitter Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb Selects the second cluster from `cluster_idx`, extracts the SMILES strings for molecules within that cluster, converts them to RDKit molecule objects, and generates a grid image for visualization. This demonstrates the structural similarity of molecules grouped together by the Lo Splitter. ```python # Visualize a cluster cluster_smiles = data.iloc[cluster_idx[1]]['smiles'] molecules = [Chem.MolFromSmiles(smiles) for smiles in cluster_smiles] img = Draw.MolsToGridImage(molecules, molsPerRow=5, subImgSize=(300, 300)) img ``` -------------------------------- ### Load FreeSolv Dataset for Stratified Distribution Splitting Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This snippet loads the `freesolv` dataset using `datamol`, which is commonly used for solubility prediction tasks. It then displays the first 5 rows to inspect the data structure, preparing for stratified splitting based on experimental values. ```python # load dataset data = dm.data.freesolv() data.head(5) ``` -------------------------------- ### Initialize LoSplitter with custom parameters and perform data split Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb This snippet demonstrates how to instantiate the `LoSplitter` with specific configuration parameters: `threshold` for Tanimoto similarity, `min_cluster_size` for cluster minimums, `max_clusters` for limiting the number of clusters, and `std_threshold` for controlling intracluster variation. It then calls the `split` method with SMILES strings and activity values to obtain training and cluster indices. ```python # An example of different parameters lo_splitter = LoSplitter( threshold=0.6, min_cluster_size=10, max_clusters=50, std_threshold=0.2 ) train_idx, cluster_idx = lo_splitter.split(data['smiles'], data['calc']) ``` -------------------------------- ### Visualize Compound and Scaffold Distributions Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/The_Basics.ipynb Utilizes the `visualize_chemspace` function to graphically represent the distribution of compounds and their corresponding scaffolds within the chemical space. This visualization helps to understand how the scaffold split has partitioned the data, showing the 'train' and 'test' sets for both compounds and their underlying scaffolds. ```python visualize_chemspace(data, split_names=["ScaffoldSplit"]) ``` ```python visualize_chemspace(data, split_names=["ScaffoldSplit"], mol_col="scaffold") ``` -------------------------------- ### splito.simpd.run_SIMPD Function Reference Source: https://github.com/datamol-io/splito/blob/main/docs/api/simpd.md Reference for the `run_SIMPD` function within the `splito.simpd` module. This function is responsible for executing the SIMPD process. ```APIDOC splito.simpd.run_SIMPD ``` -------------------------------- ### Run Splito tests locally Source: https://github.com/datamol-io/splito/blob/main/README.md Executes the comprehensive test suite for the Splito project using pytest, ensuring code functionality and stability. ```bash pytest ``` -------------------------------- ### Load ChEMBL Drugs Dataset for Molecular Weight Splitting Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This code loads the `chembl_drugs` dataset using `datamol`, which is a common dataset for cheminformatics tasks. It then displays the first 5 rows to inspect the data structure, preparing for molecular weight-based splitting. ```python # load dataset data = dm.data.chembl_drugs() data.head(5) ``` -------------------------------- ### Evaluate model performance using Spearman's correlation on a cluster Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb Demonstrates the evaluation workflow using the Lo Splitter's output. It trains a placeholder model, makes predictions on a selected test cluster, and calculates Spearman's correlation coefficient between the true and predicted property values within that cluster. This metric assesses the model's ability to correctly rank molecules based on their properties. ```python train_data = data.iloc[train_idx] model = train_model(train_data) cluster = data.iloc[cluster_idx[0]] # the first cluster cluster_preds = predict(model, cluster) cluster_true = cluster['calc'] spearmanr(cluster_true, cluster_preds)[0] ``` -------------------------------- ### Visualize molecules within a selected cluster Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb This snippet visualizes the molecules within the first cluster. It extracts SMILES strings, converts them into RDKit molecule objects, and then uses `rdkit.Chem.Draw.MolsToGridImage` to generate a grid image of these molecules for visual inspection. ```python # Visualize the cluster cluster_smiles = data.iloc[cluster_idx[0]]['smiles'] molecules = [Chem.MolFromSmiles(smiles) for smiles in cluster_smiles] img = Draw.MolsToGridImage(molecules, molsPerRow=5, subImgSize=(300, 300)) img ``` -------------------------------- ### Apply MolecularWeightSplit to Partition Chemical Dataset Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This snippet demonstrates the application of `splito.MolecularWeightSplit`. It initializes the splitter with a test size, random state, and a flag to generalize to larger molecules. It then performs the split on the SMILES data and assigns 'train' or 'test' labels to the original DataFrame based on the generated indices. ```python splitter = splito.MolecularWeightSplit(test_size=0.2, random_state=111, generalize_to_larger=True) train_idx, test_idx = next(splitter.split(X=data.smiles.tolist())) assert train_idx.shape[0] > test_idx.shape[0] data.loc[train_idx, "MolecularWeightSplit"] = "train" data.loc[test_idx, "MolecularWeightSplit"] = "test" ``` -------------------------------- ### Defining Candidate Molecular Splitting Methods Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MOOD_Protocol.ipynb This snippet defines a dictionary of candidate molecular splitting methods, including `ShuffleSplit` from scikit-learn for random splitting, and `ScaffoldSplit`, `PerimeterSplit`, and `MaxDissimilaritySplit` from the `splito` library. These splitters are then passed to `splito.MOODSplitter` to enable evaluation of their performance. ```python # Define the candidate splitters # Since we use the scikit-learn interface, this can also be sklearn Splitters splitters = { "Random": ShuffleSplit(), "Scaffold": splito.ScaffoldSplit(dataset.mol.values), "Perimeter": splito.PerimeterSplit(), "MaxDissimilarity": splito.MaxDissimilaritySplit(), } splitter = splito.MOODSplitter(splitters) ``` -------------------------------- ### Implement PerimeterSplit for Extrapolation-Oriented Splitting Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Structure_based_Splitters.ipynb This snippet illustrates the application of `splito`'s `PerimeterSplit`, a method designed to place maximally distant data points in the test set for better extrapolation. It initializes the splitter with parameters like `test_size` and `random_state`, then applies it to the 'smiles' data to generate train and test indices, which are then used to label the original dataframe. ```python # Define PerimeterSplit splitter = splito.PerimeterSplit(n_jobs=-1, test_size=0.2, random_state=111) train_idx, test_idx = next(splitter.split(X=data["smiles"].values)) assert train_idx.shape[0] > test_idx.shape[0] data.loc[train_idx, splito.PerimeterSplit.__name__] = "train" data.loc[test_idx, splito.PerimeterSplit.__name__] = "test" ``` -------------------------------- ### Check Splito code style with ruff Source: https://github.com/datamol-io/splito/blob/main/README.md Performs static code analysis and linting on the Splito codebase using ruff, identifying potential issues and enforcing coding standards. ```bash ruff check ``` -------------------------------- ### Execute Scaffold Split and Process Indices Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/The_Basics.ipynb Performs the scaffold-based split using the configured `splitter` object, obtaining the training and testing indices. An assertion is included to verify that the training set is larger than the test set, as expected with a 0.2 test size. ```python train_idx, test_idx = next(splitter.split(X=data["smiles"].values)) assert train_idx.shape[0] > test_idx.shape[0] ``` -------------------------------- ### Visualize Chemical Space Partitioned by Molecular Weight Split Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This code calls a utility function `visualize_chemspace` to visually represent the chemical space of the dataset, highlighting the partitions created by the `MolecularWeightSplit`. This helps in understanding how the split affects the overall chemical diversity in train and test sets. ```python visualize_chemspace(data, split_names=["MolecularWeightSplit"]) ``` -------------------------------- ### Visualize Chemical Space Partitioned by Stratified Distribution Split Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This code calls the `visualize_chemspace` utility function to visually represent the chemical space of the dataset, highlighting the partitions created by the `StratifiedDistributionSplit`. This helps in understanding the spatial distribution of molecules after the stratified split. ```python visualize_chemspace(data, split_names=["StratifiedDistributionSplit"]) ``` -------------------------------- ### Visualize Density Distribution of Experimental Values in Train/Test Sets Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This snippet generates density plots for the 'expt' (experimental) values, grouped by the 'StratifiedDistributionSplit' column. This visualization is crucial for verifying that the `StratifiedDistributionSplit` successfully maintained similar distributions of the target property across the train and test sets. ```python data.groupby(by="StratifiedDistributionSplit")["expt"].plot.density(legend=True) ``` -------------------------------- ### Configure splito for basic train_test_split filter Source: https://github.com/datamol-io/splito/blob/main/docs/api/splito.md This YAML configuration demonstrates the basic usage of the `splito` tool. It specifies that only the `train_test_split` filter should be applied, enabling a standard data splitting operation. ```YAML options: filters: ["train_test_split"] ``` -------------------------------- ### Visualize Solubility Classification Distribution Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Generates a histogram to visualize the distribution of the 'SOL' column, grouped by 'SOL_classification'. This helps in understanding the data's inherent structure before processing. ```python data.groupby("SOL_classification")["SOL"].hist(bins=20) ``` -------------------------------- ### Access and display a specific cluster from the dataset Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Lo_splitter.ipynb This code snippet shows how to retrieve and display the data points belonging to the first identified cluster (`cluster_idx[0]`) from the original `data` DataFrame using pandas `iloc` indexing. ```python data.iloc[cluster_idx[0]] ``` -------------------------------- ### Visualize Molecular Weight Distribution of Train/Test Sets Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This snippet generates histograms of molecular weights for the 'train' and 'test' sets, grouped by the 'MolecularWeightSplit' column. This visualization helps to confirm the distribution of molecular weights after the split, especially for the `generalize_to_larger` setting. ```python data.groupby(by="MolecularWeightSplit")["mw"].hist(legend=True) ``` -------------------------------- ### Convert Solubility Classification to Binary Format Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Transforms the 'SOL_classification' column into a binary format required by `SIMPDSplitter`. Values marked as '(C) high' are set to 1 (positive), while all other values are set to 0 (negative). ```python data.loc[data["SOL_classification"] == "(C) high", data_col] = 1 data.loc[data["SOL_classification"] != "(C) high", data_col] = 0 ``` -------------------------------- ### Assign Split Labels and Extract Scaffolds to DataFrame Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/The_Basics.ipynb Applies the generated training and testing indices back to the original `data` DataFrame, creating a new 'ScaffoldSplit' column to label each entry as 'train' or 'test'. Additionally, it extracts and stores the computed scaffolds into a new 'scaffold' column in the DataFrame. ```python data.loc[train_idx, "ScaffoldSplit"] = "train" data.loc[test_idx, "ScaffoldSplit"] = "test" data["scaffold"] = splitter.scaffolds ``` -------------------------------- ### Implement MaxDissimilaritySplit for Maximizing Train-Test Distance Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Structure_based_Splitters.ipynb This code demonstrates the use of `splito`'s `MaxDissimilaritySplit`, which aims to maximize the dissimilarity between the train and test sets. The splitter is configured with `test_size` and `random_state`, then applied to the 'smiles' data. The resulting train and test indices are used to assign corresponding labels within the dataframe. ```python # Define PerimeterSplit splitter = splito.MaxDissimilaritySplit(n_jobs=-1, test_size=0.2, random_state=111) train_idx, test_idx = next(splitter.split(X=data.smiles.values)) assert train_idx.shape[0] > test_idx.shape[0] data.loc[train_idx, "MaxDissimilaritySplit"] = "train" data.loc[test_idx, "MaxDissimilaritySplit"] = "test" ``` -------------------------------- ### splito.simpd.SIMPDSplitter Class Reference Source: https://github.com/datamol-io/splito/blob/main/docs/api/simpd.md Reference for the `SIMPDSplitter` class within the `splito.simpd` module. This class is likely used for splitting data based on SIMPD principles. ```APIDOC splito.simpd.SIMPDSplitter ``` -------------------------------- ### splito.simpd.DEFAULT_SIMPD_DESCRIPTORS Constant Reference Source: https://github.com/datamol-io/splito/blob/main/docs/api/simpd.md Reference for the `DEFAULT_SIMPD_DESCRIPTORS` constant within the `splito.simpd` module. This constant likely defines a set of default descriptors used in SIMPD calculations. ```APIDOC splito.simpd.DEFAULT_SIMPD_DESCRIPTORS ``` -------------------------------- ### Define Column Names for Data and Molecule Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/MPO_Splitters.ipynb Assigns string literals to variables `data_col` and `mol_col` to specify the column names for classification data and molecular structures within the DataFrame. This improves code readability and maintainability. ```python data_col = "CLASS_SOL" mol_col = "mol" ``` -------------------------------- ### Calculate Molecular Weight for Chemical Structures Source: https://github.com/datamol-io/splito/blob/main/docs/tutorials/Other_Splitters.ipynb This code calculates the molecular weight for each SMILES string in the dataset. It uses `datamol`'s `to_mol` to convert SMILES to RDKit molecules and then `descriptors.mw` to compute the molecular weight, storing the results in a new 'mw' column. ```python data["mw"] = data.smiles.apply(lambda smi: dm.descriptors.mw(dm.to_mol(smi))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.