Lesson · 40 min · Free
Deep Learning: NN & Data Preprocessing
Lesson: Deep Learning: NN & Data Preprocessing body { font-family: sans-serif; line-height: 1.6; margin: 20px; } h1 { color: #2c3e50; } h2 { color: #34495e; border-bottom: 2px solid #ccc; padding-bottom: 5px; margin-top:
Deep Learning: Neural Networks & Data Preprocessing
Welcome to this module on Deep Learning within the context of AI in Drug Discovery. Deep learning, a specialized subset of machine learning, has revolutionized various fields, and its application in pharmaceutical research is rapidly expanding. At its core, deep learning leverages artificial neural networks (ANNs) with multiple layers to learn complex patterns from data. For pharmacy and biotech students, understanding not just what deep learning is, but how to prepare biological and chemical data for these powerful models is crucial. Neural Networks (NNs) are inspired by the human brain's structure. They consist of interconnected nodes (neurons) organized into layers: an input layer, one or more hidden layers, and an output layer. Each connection has a weight, and each neuron has an activation function. During training, the network adjusts these weights and biases to minimize the difference between its predictions and the actual target values. This process, often involving backpropagation and gradient descent, allows the network to learn intricate relationships within the data, making it particularly adept at tasks like predicting drug-target interactions, identifying potential drug candidates, or analyzing complex omics data.
Data Preprocessing for Deep Learning in Drug Discovery
Before any deep learning model can be trained effectively, the raw data must undergo rigorous preprocessing. This step is arguably the most critical, especially in drug discovery where data can be heterogeneous, noisy, and high-dimensional. Improperly prepared data can lead to poor model performance, misleading results, and wasted computational resources. For chemical and biological data, this often involves several key stages: Data Collection and Cleaning: Sourcing data from public databases (e.g., PubChem, ChEMBL, PDB, TCGA) or experimental assays. This involves handling missing values (imputation or removal), correcting errors, and removing duplicates. Feature Engineering/Representation: Converting raw chemical structures or biological sequences into a numerical format that neural networks can understand. Chemical Structures: Molecules can be represented using SMILES strings, molecular fingerprints (e.g., ECFP4, RDKit fingerprints), or graph-based representations. Fingerprints are binary vectors indicating the presence or absence of specific substructures. Graph representations treat atoms as nodes and bonds as edges, which is particularly suitable for Graph Neural Networks (GNNs). Biological Sequences: Proteins and DNA/RNA sequences can be one-hot encoded, embedded using techniques like Word2Vec (adapted for biological sequences), or represented by physicochemical properties of residues. Normalization and Scaling: Ensuring that features contribute equally to the learning process. Features with larger ranges can dominate the loss function. Common techniques include: Min-Max Scaling: Scales features to a fixed range, usually 0 to 1. Standardization (Z-score normalization): Scales features to have zero mean and unit variance. Handling Imbalanced Data: In drug discovery, positive hits (active compounds) are often far fewer than negative hits (inactive compounds). Techniques like oversampling (SMOTE), undersampling, or using custom loss functions can address this. Splitting Data: Dividing the dataset into training, validation, and test sets. The training set is used to train the model, the validation set to tune hyperparameters and prevent overfitting, and the test set to evaluate the final model's performance on unseen data. A common split is 70% train, 15% validation, 15% test.
Code Example: Simple Data Standardization using Scikit-learn
Here's a Python example demonstrating how to standardize numerical features using the StandardScaler from scikit-learn. Imagine we have a dataset of compounds with features like molecular weight, logP, and TPSA. import pandas as pd from sklearn.preprocessing import StandardScaler from sklearn.model_selection import train_test_split # Sample data: molecular features for hypothetical compounds data = { 'Molecular_Weight': [250.3, 301.5, 189.1, 420.0, 290.7, 150.0], 'LogP': [2.5, 3.8, 1.2, 4.5, 3.1, 0.8], 'TPSA': [60.1, 85.3, 35.0, 110.5, 70.2, 25.0], 'Activity': [1, 0, 1, 0, 1, 0] # Target variable (e.g., active/inactive) } df = pd.DataFrame(data) # Separate features (X) and target (y) X = df[['Molecular_Weight', 'LogP', 'TPSA']] y = df['Activity'] # Split the data into training and test sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Initialize the StandardScaler scaler = StandardScaler() # Fit the scaler on the training data and transform both training and test data X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test) print("Original X_train (first 3 rows):") print(X_train.head(3)) print("\nScaled X_train (first 3 rows):") print(pd.DataFrame(X_train_scaled, columns=X.columns).head(3)) print("\nMean of scaled features (should be close to 0):") print(X_train_scaled.mean(axis=0)) print("\nStandard deviation of scaled features (should be close to 1):") print(X_train_scaled.std(axis=0))
Code Example: Generating Molecular Fingerprints with RDKit
This example demonstrates how to convert SMILES strings into ECFP4 molecular fingerprints using RDKit, a widely used cheminformatics library. These fingerprints can then serve as input features for a neural network. from rdkit import Chem from rdkit.Chem import AllChem import numpy as np # Sample SMILES strings smiles_list = [ "CCO", # Ethanol "CC(=O)Oc1ccccc1C(=O)O", # Aspirin "C1CCCCC1", # Cyclohexane "CN1C=NC2=C1C(=O)N(C)C(=O)N2C" # Caffeine ] # Function to generate ECFP4 fingerprints def generate_ecfp_fingerprints(smiles_list, radius=2, nBits=2048): fingerprints = [] for smiles in smiles_list: mol = Chem.MolFromSmiles(smiles) if mol is not None: # Generate Morgan fingerprint (ECFP is a type of Morgan fingerprint) # radius=2 corresponds to ECFP4 (2*2=4) fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=radius, nBits=nBits) fingerprints.append(np.array(fp)) else: fingerprints.append(np.zeros(nBits, dtype=int)) # Handle invalid SMILES return np.array(fingerprints) # Generate fingerprints ecfp4_fingerprints = generate_ecfp_fingerprints(smiles_list) print("SMILES strings:") for s in smiles_list: print(s) print("\nGenerated ECFP4 Fingerprints (first 5 bits of each):") for i, fp in enumerate(ecfp4_fingerprints): print(f"Compound {i+1}: {fp[:5]} ... (length: {len(fp)})") # Example: Check the sum of bits for a fingerprint (number of features present) print(f"\nSum of bits for Aspirin's fingerprint: {ecfp4_fingerprints[1].sum()}")
Key Takeaways
Deep Learning utilizes multi-layered Neural Networks to learn complex patterns, highly valuable in drug discovery for tasks like prediction and classification. Neural Networks consist of interconnected layers of neurons, adjusting weights and biases through training to minimize prediction errors. Data Preprocessing is paramount in drug discovery, transforming raw, heterogeneous chemical/biological data into a suitable format for NN input. Key preprocessing steps include cleaning, feature engineering (e.g., molecular fingerprints, sequence embeddings), scaling/normalization, and data splitting . Molecular fingerprints and sequence representations are common methods to convert chemical structures and biological sequences into numerical vectors for NNs. Proper data splitting (train, validation, test) is essential for robust model evaluation and preventing overfitting.
Practice Exercise
Imagine you are working on a project to predict the toxicity of novel compounds. You have a dataset containing SMILES strings, molecular weight, and a binary toxicity label (0 for non-toxic, 1 for toxic). Describe the sequence of data preprocessing steps you would take to prepare this data for a deep learning model. Be specific about the type of feature representation you would choose for the SMILES strings and why, and discuss how you would handle potential class imbalance if you expect far fewer toxic compounds than non-toxic ones.
Watch the full lesson — free
This topic is part of AI in Drug Discovery, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →