This project provides a comprehensive data preprocessing pipeline for cleaning, transforming, and preparing energy consumption datasets for analysis and machine learning modeling. The pipeline is demonstrated on three different energy-related datasets and includes steps for handling missing values, outlier removal, feature engineering, categorical variable encoding, and normalization/scaling.
The following datasets are used to showcase the preprocessing pipeline:
-
Individual Household Electric Power Consumption: This dataset contains measurements of electric power consumption in one household with a one-minute sampling rate over a period of almost 4 years. It is sourced from the UCI Machine Learning Repository.
-
Appliances Energy Prediction: This dataset contains experimental data used to create regression models of appliances energy use in a low energy building.
-
Smart Home Energy Consumption: This dataset contains energy consumption data from a smart home, including usage for various appliances and outdoor temperature readings.
The pipeline consists of the following key steps, applied to each dataset:
Missing values in the datasets are identified and handled. For numerical columns, missing values are replaced with the median, while for categorical columns, they are replaced with the mode.
Outliers are detected and removed using the Interquartile Range (IQR) method to prevent them from skewing the analysis and subsequent modeling.
New features are created from existing data:
- Converting date and time strings into datetime objects
- Extracting time-based features like hour, day_of_week, and month
- Creating additional meaningful features based on domain knowledge
Categorical variables are converted to numerical format:
- One-hot encoding for nominal categorical features
- Label encoding for ordinal categorical features
Numerical features are scaled to ensure they contribute equally to the analysis:
- MinMaxScaler is used to normalize features to a [0,1] range
- StandardScaler is used to standardize features to have zero mean and unit variance
Each dataset undergoes exploratory data analysis both before and after preprocessing:
- Distribution analysis using histograms and KDE plots
- Outlier visualization using box plots
- Relationship exploration using scatter plots
- Statistical summary of key metrics
The preprocessing pipeline successfully:
- Removes missing values and outliers
- Creates meaningful features from raw data
- Normalizes numerical features
- Encodes categorical variables
- Produces clean, analysis-ready datasets