Skip to content

SOP-005: Data Preprocessing

DOCUMENT CONTROL

FieldValue
SOP IDSOP-005
Version1.0
StatusActive

INFO

Data Preprocessing SOP for Vertex AI

Document Version: 1.0 Author: [Your Name] Last Updated: [Date]

Purpose

This Standard Operating Procedure (SOP) document provides a detailed guide on how to preprocess and prepare data for use with Vertex AI. The steps outlined in this document aim to ensure that the data is in the proper format, cleaned, and ready for use in Vertex AI models.

Procedure Flowchart

┌───────────────────┐
│ Start Data        │
│ Preprocessing    │
└───────────────────┘

┌───────────────────┐
│ 1. Identify Data  │
│ Sources           │
└───────────────────┘

┌───────────────────┐
│ 2. Explore and    │
│ Understand Data   │
└───────────────────┘

┌───────────────────┐
│ 3. Clean and      │
│ Preprocess Data   │
└───────────────────┘

┌───────────────────┐
│ 4. Validate Data  │
│ Quality           │
└───────────────────┘

┌───────────────────┐
│ 5. Split Data     │
│ into Train/Val/   │
│ Test Sets        │
└───────────────────┘

┌───────────────────┐
│ End Data          │
│ Preprocessing    │
└───────────────────┘

Procedure

1. Identify Data Sources

WARNING

Ensure that you have the necessary permissions and access to the data sources.

  1. Identify the data sources that you will be using for your Vertex AI project.
  2. Determine the format of the data (e.g., CSV, JSON, images, etc.) and any relevant metadata.
  3. Assess the quality and completeness of the data.

2. Explore and Understand Data

  1. Load the data into a Python environment (e.g., Jupyter Notebook, Google Colab) using appropriate libraries such as Pandas or TensorFlow.
  2. Perform exploratory data analysis (EDA) to understand the characteristics of the data, including:
    • Data types and shape
    • Missing values
    • Outliers
    • Correlation between features
    • Class imbalance (for classification tasks)

Example code:

python
import pandas as pd

# Load data
df = pd.read_csv('data.csv')

# Perform EDA
print(df.info())
print(df.describe())
print(df.isnull().sum())

3. Clean and Preprocess Data

  1. Handle missing values:
    • Impute missing values using appropriate techniques (e.g., mean, median, mode, or more advanced methods like MICE or KNN imputation).
    • Drop rows or columns with excessive missing values.

Example code:

python
# Handle missing values
df['column_name'] = df['column_name'].fillna(df['column_name'].mean())
  1. Encode categorical features:
    • Use one-hot encoding or label encoding for categorical variables.

Example code:

python
from sklearn.preprocessing import OneHotEncoder

# Encode categorical features
encoder = OneHotEncoder()
X_encoded = encoder.fit_transform(df[['categorical_column']]).toarray()
  1. Scale numerical features:
    • Apply feature scaling techniques such as standardization (z-score) or normalization (min-max scaling).

Example code:

python
from sklearn.preprocessing import StandardScaler

# Scale numerical features
scaler = StandardScaler()
X_scaled = scaler.fit_transform(df[['numerical_column']])
  1. Handle imbalanced datasets:
    • Use techniques like oversampling (e.g., SMOTE), undersampling, or class weighting to address class imbalance.

Example code:

python
from imblearn.over_sampling import SMOTE

# Oversample minority class
smote = SMOTE()
X_resampled, y_resampled = smote.fit_resample(X, y)
  1. Engineer new features:
    • Create additional features based on the domain knowledge and the problem you're trying to solve.

Example code:

python
# Engineer new feature
df['new_feature'] = df['feature1'] + df['feature2']

4. Validate Data Quality

  1. Verify that the data is in the correct format and structure.
  2. Ensure that there are no remaining missing values or outliers.
  3. Check that the feature engineering and preprocessing steps have been applied correctly.

Example code:

python
# Validate data quality
assert df.isnull().sum().sum() == 0, "Missing values found in the data"
assert len(df) == len(df.dropna()), "Rows with missing values present"

5. Split Data into Train/Validation/Test Sets

  1. Split the preprocessed data into training, validation, and test sets using an appropriate library like scikit-learn.
  2. Ensure that the split is representative of the entire dataset and maintains the class distribution (if applicable).

Example code:

python
from sklearn.model_selection import train_test_split

# Split data into train, validation, and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.25, random_state=42)

Verification Checklist

  • [ ] Data sources have been identified and accessed
  • [ ] Exploratory data analysis has been performed
  • [ ] Missing values have been handled
  • [ ] Categorical features have been encoded
  • [ ] Numerical features have been scaled
  • [ ] Imbalanced datasets have been addressed (if applicable)
  • [ ] New features have been engineered (if applicable)
  • [ ] Data quality has been validated
  • [ ] Data has been split into train/validation/test sets

Troubleshooting

IssuePossible CauseResolution
Missing values in the dataset- Data was not collected properly
- Errors during data entry or processing
- Impute missing values using appropriate techniques
- Drop rows or columns with excessive missing values
Imbalanced dataset- The distribution of classes in the dataset is not equal- Apply oversampling, undersampling, or class weighting techniques to address the imbalance
Outliers in the data- Errors in data collection or entry
- Unusual observations in the data
- Identify and remove outliers using appropriate methods (e.g., Z-score, IQR, or more advanced techniques)
Incorrect data format- Data was not saved in the expected format- Convert the data to the correct format (e.g., CSV, JSON, image files)
Errors during feature engineering- Incorrect assumptions or implementation of new features- Review the feature engineering logic and make necessary corrections

DANGER

It is crucial to thoroughly test and validate the preprocessed data before using it in your Vertex AI models. Any issues with the data can significantly impact the performance and reliability of your models.

See Also