Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 70 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,79 @@
# Battery Life Prediction using Machine Learning

## Project Overview
This project aims to predict battery life for various electronic devices using machine learning techniques. The dataset is preprocessed to extract key features, and multiple regression models are trained to estimate battery life accurately. The project includes single-model training and pairwise ensemble model training for better predictive performance.

## Project Structure
- `device_battery_data.xlsx`: Dataset containing battery performance metrics for different devices.
- `Single_Models.py`: Script to train and evaluate individual machine learning models.
- `Pair_Models.py`: Script to train and evaluate ensemble models using pairwise stacking regressors.

## Features and Preprocessing
The dataset includes features such as:
- **Battery Capacity (mAh)** and **Battery Voltage (V)** to calculate total battery energy.
- **Charging Cycles**, **Device Age**, and **Battery Lifespan** to compute battery degradation.
- **Operating Temperature** and **Environmental Conditions** to adjust for external factors.
- **Power Consumption in Active and Sleep Modes** to estimate daily energy usage.

Feature engineering steps include:
- Computing `Battery_Degradation_Factor` using charging cycles and device age.
- Calculating `Average_Power_Consumption` based on usage patterns.
- Scaling features using `StandardScaler`.
- Handling missing values and removing outliers using IQR filtering.

## Models Implemented
### Single Model Training (`Single_Models.py`)
The following models are trained and evaluated using cross-validation:
- Linear Regression, Lasso, Ridge, ElasticNet
- Decision Tree, Random Forest, Gradient Boosting, XGBoost
- Support Vector Regression, K-Nearest Neighbors
- AdaBoost, Bagging, Extra Trees

Some models are fine-tuned using `RandomizedSearchCV` for hyperparameter optimization.

### Pairwise Ensemble Training (`Pair_Models.py`)
- Pairs of models are combined using `StackingRegressor` to improve performance.
- Ridge Regression is used as the final estimator.
- Each model pair is evaluated on MSE, MAE, and R² scores.

## Running the Code
Ensure you have the required dependencies installed:
```markdown
# Palindrome Checker Script

## Overview

This Python script, `palindrome.py`, checks if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.

## File: `palindrome.py`

### Description

The script initializes a string `s` with the value "malayalam". It then uses two pointers, `i` and `j`, to traverse the string from the beginning and the end, respectively. The script iterates through the string, comparing characters at the `i`-th and `j`-th positions. If a mismatch is found, a flag `is_palindrome` is set to `False`, and the loop breaks. Finally, the script prints "Yes" if the string is a palindrome and "No" otherwise.

### Usage

To execute the script, run the following command in your terminal:

```bash
pip install numpy pandas scikit-learn xgboost joblib openpyxl
python palindrome.py
```

To run single-model training:
```bash
python Single_Models.py
### Variables

* `s`: A string variable initialized to "malayalam". This is the string to be checked for palindrome properties.
* `i`: An integer variable used as a pointer to the beginning of the string.
* `j`: An integer variable used as a pointer to the end of the string.
* `is_palindrome`: A boolean variable initialized to `True`. It is set to `False` if the string is not a palindrome.

### Algorithm

1. Initialize `s` to "malayalam".
2. Initialize `i` to 0 (start of the string) and `j` to `len(s) - 1` (end of the string).
3. Initialize `is_palindrome` to `True`.
4. While `i` is less than `j`:
* If the character at index `i` in `s` is not equal to the character at index `j` in `s`:
* Set `is_palindrome` to `False`.
* Break out of the loop.
* Increment `i`.
* Decrement `j`.
5. If `is_palindrome` is `True`:
* Print "Yes".
6. Else:
* Print "No".

### Example

When the script is executed, it will output:

```
To run pairwise model training:
```bash
python Pair_Models.py
Yes
```

## Evaluation Metrics
Models are evaluated using:
- **Mean Squared Error (MSE)**: Measures prediction error.
- **Mean Absolute Error (MAE)**: Measures average absolute error.
- **R² Score**: Measures the proportion of variance explained by the model.
This is because the string "malayalam" is a palindrome.

### Potential Improvements

## Future Improvements
- Implement deep learning models using TensorFlow/PyTorch.
- Experiment with Quantum Neural Networks (QNN) using Qiskit.
- Incorporate real-time battery performance monitoring.
* **Input Flexibility:** The script could be modified to take input from the user or read the string from a file, making it more versatile.
* **Case Insensitivity:** The script could be made case-insensitive by converting the string to lowercase before checking for palindrome properties (e.g., using `s.lower()`).
* **Handling Spaces and Punctuation:** The script could be extended to handle strings with spaces and punctuation by removing them before checking for palindrome properties.
* **Function Encapsulation:** The palindrome checking logic could be encapsulated into a function for reusability.

```python
def is_palindrome(s):
"""Checks if a string is a palindrome (case-insensitive, ignores spaces)."""
processed_string = ''.join(filter(str.isalnum, s)).lower()
return processed_string == processed_string[::-1]

string_to_check = "A man, a plan, a canal: Panama"
if is_palindrome(string_to_check):
print("Yes")
else:
print("No")

string_to_check = "hello"
if is_palindrome(string_to_check):
print("Yes")
else:
print("No")
```