This project implements a Hybrid CNN-LSTM Deep Learning Pipeline for classifying electrical faults in transmission lines using time-series voltage and current measurements.
Pipeline Architecture:
Raw CSV Data → Preprocessing → Time Windows → CNN (Feature Extraction) → LSTM (Temporal Learning) → Dense (Classification) → Fault Prediction
- Source:
classData.csv - Samples: 7,861 measurements
- Features: 6 (Ia, Ib, Ic, Va, Vb, Vc)
Ia,Ib,Ic: Current measurements for phases A, B, CVa,Vb,Vc: Voltage measurements for phases A, B, C
- Target: 4 binary columns (G, C, B, A) combined into 6 fault types
- Classes:
0000: No Fault1001: LG Fault (Line-Ground)0011: LL Fault (Line-Line)1011: LLG Fault (Line-Line-Ground)0111: LLL Fault (Three-phase)1111: LLLG Fault (Three-phase symmetrical)
pip install tensorflow numpy pandas scikit-learn matplotlib seabornRecommended versions:
- Python 3.8+
- TensorFlow 2.10+
- NumPy 1.23+
- Pandas 1.5+
- Scikit-learn 1.2+
For faster training, install TensorFlow with GPU support:
pip install tensorflow-gpusamuel CNN/
├── classData.csv # Dataset
├── cnn_lstm_preprocessing.py # Data preprocessing module
├── cnn_lstm_model.py # Model architecture module
├── train_cnn_lstm.py # Training script
├── evaluate_model.py # Evaluation script
├── README_CNN_LSTM.md # This file
│
├── best_cnn_lstm_model.h5 # Trained model (generated)
├── scaler.pkl # Fitted scaler (generated)
├── label_encoder.pkl # Label encoder (generated)
├── training_history.csv # Training metrics (generated)
├── hyperparameters_log.json # Hyperparameters (generated)
│
└── Visualizations (generated):
├── confusion_matrix.png
├── training_history.png
├── classwise_f1_scores.png
└── training_summary.png
cd "c:\Users\HP\Downloads\samuel CNN"
python cnn_lstm_preprocessing.pyExpected output:
- Data loading confirmation
- Sequence generation statistics
- Shape validation results
python cnn_lstm_model.pyExpected output:
- Model architecture summary
- Parameter counts
- Quick training test results
python train_cnn_lstm.pyTraining process:
- Loads and preprocesses data
- Creates time-series sequences (TIME_STEPS=10)
- Builds CNN-LSTM model
- Trains with early stopping and learning rate reduction
- Saves best model and training artifacts
Expected duration:
- CPU: 5-15 minutes
- GPU: 1-3 minutes
Generated files:
best_cnn_lstm_model.h5training_history.csvhyperparameters_log.jsonscaler.pkllabel_encoder.pklmodel_architecture.txttraining_summary.png
python evaluate_model.pyEvaluation includes:
- Overall accuracy, precision, recall, F1-score
- Class-wise performance metrics
- Confusion matrix
- Training history visualization
- Class-wise F1 score comparison
Generated files:
confusion_matrix.pngtraining_history.pngclasswise_f1_scores.pngevaluation_metrics.txt
| Parameter | Value | Description |
|---|---|---|
| Data | ||
TIME_STEPS |
10 | Sequence length for sliding window |
TEST_SIZE |
0.2 | Test set proportion |
VALIDATION_SPLIT |
0.2 | Validation split during training |
| Model Architecture | ||
CNN_FILTERS_1 |
64 | First Conv1D layer filters |
CNN_FILTERS_2 |
128 | Second Conv1D layer filters |
CNN_KERNEL_SIZE |
3 | Convolutional kernel size |
LSTM_UNITS |
100 | LSTM layer units |
DROPOUT_RATE |
0.3 | Dropout rate for regularization |
DENSE_UNITS |
64 | Dense layer units |
| Training | ||
BATCH_SIZE |
32 | Training batch size |
EPOCHS |
50 | Maximum training epochs |
LEARNING_RATE |
0.001 | Adam optimizer learning rate |
EARLY_STOPPING_PATIENCE |
10 | Early stopping patience |
Edit the HYPERPARAMETERS dictionary in train_cnn_lstm.py:
HYPERPARAMETERS = {
'TIME_STEPS': 15, # Try 5, 10, 15, 20
'LSTM_UNITS': 150, # Try 50, 100, 150, 200
'BATCH_SIZE': 64, # Try 16, 32, 64, 128
# ... other parameters
}Input: (10 timesteps, 6 features)
↓
Conv1D (64 filters, kernel=3, ReLU)
↓
BatchNormalization
↓
MaxPooling1D (pool_size=2)
↓
Dropout (0.3)
↓
Conv1D (128 filters, kernel=3, ReLU)
↓
BatchNormalization
↓
MaxPooling1D (pool_size=2)
↓
Dropout (0.3)
↓
LSTM (100 units, dropout=0.3, recurrent_dropout=0.2)
↓
Dense (64 units, ReLU)
↓
Dropout (0.4)
↓
Dense (6 units, Softmax)
↓
Output: Fault class probabilities
Total Parameters: ~150,000 (varies with configuration)
The cnn_lstm_model.py module also provides:
- Lightweight model: Faster training, fewer parameters
- Deep model: More layers, potentially higher accuracy
- Accuracy: ≥95%
- Precision: ≥94%
- Recall: ≥94%
- F1-Score: ≥94%
| Model | Accuracy | Training Time | Parameters |
|---|---|---|---|
| RandomForest (baseline) | ~99% | <1 min | N/A |
| CNN-LSTM (this project) | ~95-98% | 5-15 min | ~150K |
Note: The CNN-LSTM model demonstrates deep learning techniques for time-series classification. While RandomForest may achieve higher accuracy on this dataset, the CNN-LSTM approach is valuable for:
- Learning temporal patterns
- Handling sequential data
- Demonstrating modern deep learning architectures
Problem: Out of memory during training
Solutions:
- Reduce
BATCH_SIZE(try 16 or 8) - Reduce
TIME_STEPS(try 5 or 7) - Use lightweight model variant
Problem: Model accuracy < 90%
Solutions:
- Increase
EPOCHS(try 100) - Adjust
LEARNING_RATE(try 0.0005 or 0.002) - Increase model complexity (use deep model variant)
- Increase
TIME_STEPS(try 15 or 20)
Problem: Training accuracy >> Validation accuracy
Solutions:
- Increase
DROPOUT_RATE(try 0.4 or 0.5) - Add L2 regularization
- Reduce model complexity
- Increase training data (if possible)
Problem: Training takes too long
Solutions:
- Use GPU acceleration
- Reduce
BATCH_SIZE - Use lightweight model variant
- Reduce
EPOCHSwith early stopping
All experiments are reproducible using:
- Random seeds: Set in
train_cnn_lstm.py(NumPy and TensorFlow) - Hyperparameter logging: Saved in
hyperparameters_log.json - Preprocessing artifacts:
scaler.pklandlabel_encoder.pkl - Model checkpoints: Best model saved during training
To reproduce results:
python train_cnn_lstm.py # Uses fixed random_state=42
python evaluate_model.pyTo add CNN-LSTM results to notebook6c7b88094f.py:
# Add after the RandomForest multiclass classification section
# ============================================================================
# CNN-LSTM HYBRID MODEL
# ============================================================================
from cnn_lstm_preprocessing import load_and_prepare_data, normalize_features, create_sequences
from cnn_lstm_model import build_cnn_lstm_model, compile_model
import tensorflow as tf
# Load and preprocess
X, y, le = load_and_prepare_data('classData.csv')
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
X_train_norm, X_test_norm, scaler = normalize_features(X_train, X_test)
# Create sequences
TIME_STEPS = 10
X_train_seq, y_train_seq = create_sequences(X_train_norm, y_train, TIME_STEPS)
X_test_seq, y_test_seq = create_sequences(X_test_norm, y_test, TIME_STEPS)
# Build and train
model = build_cnn_lstm_model((TIME_STEPS, 6), 6)
model = compile_model(model)
history = model.fit(X_train_seq, y_train_seq, epochs=50, batch_size=32, validation_split=0.2)
# Evaluate
y_pred = np.argmax(model.predict(X_test_seq), axis=1)
print(f"CNN-LSTM Accuracy: {accuracy_score(y_test_seq, y_pred):.4f}")- Problem Statement: Electrical fault classification using time-series data
- Methodology: Hybrid CNN-LSTM architecture for temporal pattern recognition
- Pipeline: Data preprocessing → Sequence generation → CNN feature extraction → LSTM temporal learning → Classification
- Results: Accuracy, precision, recall, F1-score, confusion matrix
- Comparison: CNN-LSTM vs. RandomForest baseline
- Conclusion: Deep learning approach demonstrates effective temporal pattern learning
- Pipeline architecture diagram
- Model architecture summary
- Confusion matrix
- Training history curves
- Class-wise F1 score comparison
- TensorFlow Documentation: https://www.tensorflow.org/
- Keras Sequential API: https://keras.io/guides/sequential_model/
- Time Series Classification: https://arxiv.org/abs/1809.04356
This project is for educational purposes as part of a term paper on electrical fault classification.
For questions or issues, please refer to the implementation plan or consult the course instructor.