The ANN-Thevenin-Hybrid-Model is a hybrid machine learning model designed to predict the State of Charge (SoC) of a battery based on input features such as Voltage, Current, and Time. This model combines the predictive capabilities of Artificial Neural Networks (ANN) with the Thevenin equivalent model for enhanced accuracy and reliability.
- Data Preprocessing: Handles missing data and normalizes input features.
- ANN Model: Implements a deep neural network with multiple hidden layers.
- Custom Metrics: Utilizes SMAPE (Symmetric Mean Absolute Percentage Error) for evaluation.
- Visualization: Generates insightful plots to assess model performance.
- Model Persistence: Saves the trained model and scaler for future use.
- Prediction Functionality: Provides easy-to-use functions for making new predictions.
The model uses a dataset named battery_text.csv
, which contains the following columns:
- Voltage: Voltage of the battery (in volts).
- Current: Current flow (in amperes).
- Time: Time duration (in seconds).
- SoC: State of Charge of the battery (target variable).
Note: Ensure that the dataset is placed in the /content/
directory or update the path accordingly in the notebook.
-
Clone the Repository
git clone https://github.com/yourusername/ANN-Thevenin-Hybrid-Model.git cd ANN-Thevenin-Hybrid-Model
-
Create a Virtual Environment It's recommended to use a virtual environment to manage dependencies.
python3 -m venv venv source venv/bin/activate
Install Dependencies
pip install -r requirements.txt
Dependencies Include:
python numpy pandas matplotlib seaborn scikit-learn tensorflow pickle-mixin
- Open the Notebook: Open ann_hybrid_github.ipynb using Jupyter Notebook or Google Colab.
- Run Cells Sequentially Execute each cell in the notebook to perform data loading, preprocessing, model training, evaluation, and visualization.
- Making Predictions At the end of the notebook, there is a section for making new predictions using the trained model.
- Update the voltage, current, and time variables with your desired input values and run the prediction cell.
The ANN model is built using TensorFlow's Keras API with the following structure:
-
Input Layer: Accepts three features - Voltage, Current, and Time.
-
Hidden Layers:
- Dense layer with 64 neurons and ReLU activation.
- Dense layer with 128 neurons and ReLU activation.
- Dense layer with 128 neurons and ReLU activation.
-
Output Layer: Single neuron for predicting SoC.
-
Compilation:
- Optimizer: Adam
- Loss Function: Mean Squared Error (MSE)
- Training Parameters:
- Epochs: 100
- Batch Size: 32
-
Evaluation: After training, the model is evaluated using the following metrics:
- Mean Absolute Error (MAE)
- R² Score
- Symmetric Mean Absolute Percentage Error (SMAPE)
The notebook generates several plots to visualize the model's performance:
-
Actual vs Predicted SoC (ANN): Scatter plot comparing actual SoC values against predictions.
-
Distribution of Errors (Histogram): Shows the distribution of prediction errors.
-
Residuals vs. Predicted Values: Helps identify any patterns in the residuals.
-
Correlation Matrix: Displays correlations between Voltage, Current, Time, and SoC.
-
Neural Network Diagram: Visual representation of the ANN architecture. These visualizations aid in diagnosing model performance and understanding relationships within the data.
Saving
-
Scaler: The StandardScaler object is saved as
scaler_X.pkl
using pickle for consistent data preprocessing during inference. -
Model: The trained ANN model is saved as
hybrid_ann_thevenin_model.keras
. -
Functions are provided to load the scaler and model and make predictions with new input data.
This project is licensed under the MIT License.