Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

CNN-LSTM Electrical Fault Classification

A hybrid deep learning pipeline for classifying electrical faults in transmission lines using time-series voltage and current measurements.

πŸ“Š Project Overview

  • Model: Hybrid CNN-LSTM Architecture
  • Accuracy: 78.01% on test set
  • Dataset: 7,861 electrical measurements
  • Classes: 6 fault types (No Fault, LG, LL, LLG, LLL, LLLG)

πŸ“¦ Data Source

This project uses the Electrical Fault Detection and Classification dataset from Kaggle:

πŸ”— Reference Project

This implementation is built with reference to a previous Kaggle notebook:

πŸ“ Project Structure

A Hybrid CNN - LSTM Model for fault detection in power distribution system/
β”œβ”€β”€ src/ # Source code
β”‚ β”œβ”€β”€ README.md # Source code documentation
β”‚ β”œβ”€β”€ cnn_lstm_preprocessing.py # Data preprocessing & sequence generation
β”‚ β”œβ”€β”€ cnn_lstm_model.py # Model architecture definitions
β”‚ β”œβ”€β”€ train_cnn_lstm.py # Training pipeline
β”‚ └── evaluate_model.py # Evaluation & visualization
β”‚
β”œβ”€β”€ models/ # Trained models & artifacts
β”‚ β”œβ”€β”€ best_cnn_lstm_model.h5 # Trained model weights (1.5 MB)
β”‚ β”œβ”€β”€ scaler.pkl # Fitted StandardScaler
β”‚ └── label_encoder.pkl # Label encoder
β”‚
β”œβ”€β”€ results/ # Training results
β”‚ β”œβ”€β”€ README.md # Results documentation
β”‚ β”œβ”€β”€ visualizations/ # Generated plots
β”‚ β”‚ β”œβ”€β”€ confusion_matrix.png
β”‚ β”‚ β”œβ”€β”€ training_history.png
β”‚ β”‚ β”œβ”€β”€ classwise_f1_scores.png
β”‚ β”‚ └── training_summary.png
β”‚ └── metrics/ # Performance metrics
β”‚ β”œβ”€β”€ evaluation_metrics.txt
β”‚ β”œβ”€β”€ training_history.csv
β”‚ └── hyperparameters_log.json
β”‚
β”œβ”€β”€ data/ # Datasets
β”‚ β”œβ”€β”€ classData.csv # Multiclass fault dataset (655 KB)
β”‚ └── detect_dataset.csv # Binary fault detection dataset (952 KB)
β”‚
β”œβ”€β”€ docs/ # Documentation
β”‚ └── README_CNN_LSTM.md # Detailed technical documentation
β”‚
β”œβ”€β”€ electrical-faults-analysis-classification.ipynb # Jupyter notebook
β”œβ”€β”€ electrical-faults-analysis-classification.py # Converted Python script
β”œβ”€β”€ model_architecture.txt # Model architecture summary
β”œβ”€β”€ REFACTORING_SUMMARY.md # Project refactoring notes
└── README.md # This file

πŸš€ Quick Start

Prerequisites

pip install tensorflow numpy pandas scikit-learn matplotlib seaborn

Training

cd "c:\Users\HP\Downloads\A Hybrid CNN - LSTM Model for fault detection in power distribution system"
$env:PYTHONIOENCODING='utf-8'
python src/train_cnn_lstm.py

Evaluation

python src/evaluate_model.py

πŸ“ˆ Results

Overall Performance

  • Accuracy: 78.01%
  • Precision: 77.53%
  • Recall: 78.01%
  • F1-Score: 77.47%

Class-Wise Performance

Fault Type Accuracy F1-Score
No Fault (0000) 97.01% 95.18%
LG Fault (1001) 93.33% 88.24%
LLG Fault (1011) 88.50% 88.11%
LL Fault (0110) 80.50% 86.10%
LLL Fault (0111) 55.05% 50.21%
LLLG Fault (1111) 33.04% 38.27%

πŸ—οΈ Architecture

Model Flow Diagram

flowchart TD
 A["Raw CSV Data"] --> B["Data Loading & Preparation"]
 B --> C["Feature Extraction"]
 C --> D["Train/Test Split"]
 D --> E["StandardScaler Normalization"]
 E --> F["Sequence Generation"]
 
 F --> G["CNN-LSTM Model"]
 
 G --> H["CNN Block 1"]
 H --> I["CNN Block 2"]
 I --> J["LSTM Layer"]
 J --> K["Dense Layer"]
 K --> L["Output Layer"]
 
 L --> M["Predictions"]
 M --> N["Evaluation Metrics"]
 
 N --> O["Confusion Matrix"]
 N --> P["ROC Curves"]
 N --> Q["PR Curves"]
 N --> R["F1 Scores"]
 
 style G fill:#e1f5ff
 style H fill:#fff3e0
 style I fill:#fff3e0
 style J fill:#f3e5f5
 style K fill:#e8f5e9
 style L fill:#e8f5e9
Loading

Layer Architecture

Input (10 timesteps, 6 features)
 ↓
Conv1D (64 filters) β†’ BatchNorm β†’ MaxPool β†’ Dropout
 ↓
Conv1D (128 filters) β†’ BatchNorm β†’ MaxPool β†’ Dropout
 ↓
LSTM (100 units, dropout=0.3)
 ↓
Dense (64, ReLU) β†’ Dropout
 ↓
Dense (6, Softmax)

Parameters: 125,142 (488 KB)

Detailed Architecture: See model_architecture.txt for complete layer-by-layer breakdown

πŸ“š Documentation

For detailed documentation, see docs/README_CNN_LSTM.md

πŸ”¬ Key Features

  • βœ… Temporal Awareness: LSTM layer captures time-series patterns
  • βœ… Automatic Feature Learning: CNN extracts relevant features
  • βœ… Production Ready: Includes scaler and encoder for deployment
  • βœ… Comprehensive Evaluation: Confusion matrix, F1 scores, training curves
  • βœ… Reproducible: Fixed random seeds and hyperparameter logging

πŸ“Š Visualizations

All visualizations are automatically generated in results/visualizations/:

  • Confusion Matrix - Prediction accuracy per class with heatmap
  • Training History - Accuracy & loss curves over epochs
  • Class-wise F1 Scores - Performance comparison across fault types
  • ROC Curves - Receiver Operating Characteristic (One-vs-Rest) with AUC scores
  • PR Curves - Precision-Recall curves with Average Precision scores

Run python src/evaluate_model.py to generate all visualizations.

πŸŽ“ Academic Use

This project was developed for a term paper on electrical fault classification. The implementation demonstrates:

  • Deep learning for time-series classification
  • Hybrid CNN-LSTM architecture
  • Complete ML pipeline from preprocessing to evaluation

πŸ“ License

Educational project for academic purposes.

πŸ‘€ Author

Developed for academic purposes as part of a 400 level project on electrical fault detection and classification.

About

Hybrid CNN-LSTM deep learning model for electrical fault classification in power transmission lines. Achieves 78% accuracy across 6 fault types using time-series analysis. Includes complete ML pipeline with preprocessing, training, and evaluation tools. Built with TensorFlow & Keras.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /