Lesson · 40 min · Free
Deep Learning: From Neural Networks to Data Preprocessing
Deep Learning: From Neural Networks to Data Preprocessing body { font-family: sans-serif; line-height: 1.6; margin: 20px; } h1, h2 { color: #2c3e50; } pre { background-color: #ecf0f1; padding: 15px; border-radius: 5px; o
Deep Learning: From Neural Networks to Data Preprocessing
Welcome to this foundational lesson on Deep Learning, a subfield of machine learning inspired by the structure and function of the human brain. For those in pharmacy and biotechnology, deep learning offers powerful tools for drug discovery, personalized medicine, image analysis (e.g., microscopy, histology), and even predicting molecular interactions. We'll start by demystifying the core component – the neural network – and then move into the crucial step of preparing your valuable biological data for these sophisticated models. At its heart, a neural network is a series of interconnected nodes, or "neurons," organized in layers. Information flows from an input layer, through one or more "hidden layers," to an output layer. Each connection between neurons has a weight, and each neuron has a bias. When a neuron receives input from other neurons, it computes a weighted sum of these inputs, adds the bias, and then passes this result through an activation function. This non-linear activation function is what allows neural networks to learn complex patterns and relationships in data that linear models cannot capture, making them incredibly effective for tasks like classifying disease states from patient data or predicting protein folding. The "learning" in a neural network occurs through a process called backpropagation. Initially, the weights and biases are randomly assigned. The network makes a prediction, and the difference between this prediction and the actual target (the "error") is calculated. This error is then propagated backward through the network, and an optimization algorithm (like Gradient Descent) adjusts the weights and biases in each layer to minimize this error. This iterative process, repeated over many "epochs" (full passes through the dataset), allows the network to gradually improve its predictive accuracy. For example, in drug discovery, a neural network might learn to predict the binding affinity of a molecule to a target protein by adjusting its internal parameters based on known binding data. Before any deep learning model can be trained effectively, the data must be meticulously prepared. This stage, known as data preprocessing, is often the most time-consuming yet critical part of the entire machine learning pipeline. Raw biological and chemical data, whether it's gene expression profiles, patient demographics, molecular descriptors, or microscopic images, is rarely in a format directly suitable for a neural network. Common issues include missing values, inconsistent units, varying scales, and categorical features that need numerical encoding. Proper preprocessing ensures that the model can learn efficiently and generalize well to new, unseen data. Consider a dataset containing patient information where some entries have missing values for 'Age' or 'BMI'. Simply feeding this to a neural network would likely cause errors or lead to poor performance. Imputation techniques, such as replacing missing values with the mean, median, or a more sophisticated prediction, are necessary. Similarly, features like 'Drug Dosage' might range from milligrams to grams, while 'Patient Age' might range from 18 to 90. Without scaling, features with larger numerical ranges might disproportionately influence the learning process. Standardization or normalization brings all features to a similar scale, preventing this bias. Here’s a basic Python example demonstrating how to handle missing values and scale numerical features using scikit-learn, a popular machine learning library. Imagine you have a small dataset for predicting drug response based on patient age, BMI, and a lab marker. import pandas as pd from sklearn.impute import SimpleImputer from sklearn.preprocessing import StandardScaler # Sample data for drug response prediction data = { 'Patient_ID': [1, 2, 3, 4, 5], 'Age': [35, 42, None, 55, 28], 'BMI': [24.5, 28.1, 22.9, None, 23.7], 'Lab_Marker_A': [120, 150, 110, 180, 130], 'Drug_Response': [0, 1, 0, 1, 0] # 0 for no response, 1 for response } df = pd.DataFrame(data) print("Original DataFrame:\n", df) # 1. Handle Missing Values (Imputation) # Using mean for numerical features imputer = SimpleImputer(strategy='mean') df[['Age', 'BMI']] = imputer.fit_transform(df[['Age', 'BMI']]) print("\nDataFrame after Imputation:\n", df) # 2. Scale Numerical Features # Exclude 'Patient_ID' and 'Drug_Response' from scaling features_to_scale = ['Age', 'BMI', 'Lab_Marker_A'] scaler = StandardScaler() df[features_to_scale] = scaler.fit_transform(df[features_to_scale]) print("\nDataFrame after Scaling:\n", df) Categorical features, such as 'Gender' (Male, Female) or 'Disease_Stage' (Stage I, Stage II, Stage III), also require special attention. They cannot be directly fed into a neural network as text. One-hot encoding is a common technique where each category is converted into a binary vector. For instance, 'Gender' might become two new columns: 'Gender_Male' and 'Gender_Female', with a 1 in the respective column and 0 otherwise. This avoids implying any ordinal relationship between categories that doesn't exist. Here’s an example of one-hot encoding a categorical feature: import pandas as pd from sklearn.preprocessing import OneHotEncoder # Sample data with a categorical feature data_cat = { 'Patient_ID': [1, 2, 3, 4, 5], 'Disease_Stage': ['Stage I', 'Stage II', 'Stage I', 'Stage III', 'Stage II'], 'Drug_Response': [0, 1, 0, 1, 0] } df_cat = pd.DataFrame(data_cat) print("Original DataFrame with categorical feature:\n", df_cat) # 1. One-Hot Encode 'Disease_Stage' encoder = OneHotEncoder(handle_unknown='ignore', sparse_output=False) encoded_features = encoder.fit_transform(df_cat[['Disease_Stage']]) # Create a DataFrame from the encoded features encoded_df = pd.DataFrame(encoded_features, columns=encoder.get_feature_names_out(['Disease_Stage'])) # Concatenate with the original DataFrame (dropping the original categorical column) df_processed_cat = pd.concat([df_cat.drop('Disease_Stage', axis=1), encoded_df], axis=1) print("\nDataFrame after One-Hot Encoding:\n", df_processed_cat) The meticulous application of these preprocessing steps ensures that the neural network receives clean, consistent, and appropriately formatted data, significantly enhancing its ability to learn meaningful patterns and generalize effectively to new, unseen biological or chemical samples. This is paramount in fields where the stakes are high, such as patient diagnostics or drug efficacy prediction.
Key Takeaways
Neural networks learn complex patterns by adjusting weights and biases through backpropagation, mimicking biological neurons. Activation functions introduce non-linearity, enabling networks to model non-linear relationships in data. Data preprocessing is a critical step, involving handling missing values, scaling numerical features, and encoding categorical features. Proper data preparation is essential for efficient training, improved model performance, and reliable generalization in deep learning applications. Techniques like imputation (e.g., SimpleImputer ), scaling (e.g., StandardScaler ), and one-hot encoding (e.g., OneHotEncoder ) are fundamental tools in the preprocessing toolkit. Practice Exercise: Given a hypothetical dataset of patient gene expression levels (numerical) and disease presence (binary categorical) along with a 'Treatment_Group' (categorical: 'Placebo', 'Drug A', 'Drug B'), describe the steps you would take to preprocess this data for a deep learning model. Specifically, outline how you would handle missing values (if any), scale the gene expression data, and encode the categorical features. If you have access to Python, try to implement these steps using a small, self-generated dummy dataset.
Watch the full lesson — free
This topic is part of AI & Machine Learning Foundations, a complete AI-narrated video course. Press play once and watch the entire lecture like a movie.
Start the course free →