Skip to content

Commit

Permalink
Traffic Accident Prediction Model using Deep Learning (#585)
Browse files Browse the repository at this point in the history
## Pull Request for Traffic Accident Prediction Model ๐Ÿ›ฃ๏ธ

### Requesting to submit a pull request to the Traffic Accident
Prediction Model repository.

---

#### Issue Title
**Please enter the title of the issue related to your pull request.**  
*Traffic Accident Prediction Model using Deep Learning*

- [x] I have provided the issue title.

---

#### Info about the Related Issue
**What's the goal of the project?**  
The aim of the project is to predict the likelihood of traffic accidents
using historical data such as accident records, weather conditions,
traffic volume, and road characteristics, helping local authorities
implement targeted safety measures and improve traffic management
strategies.

- [x] I have described the aim of the project.

---

#### Name
**Please mention your name.**  
*Alolika Bhowmik*

- [x] I have provided my name.

---

#### GitHub ID
**Please mention your GitHub ID.**  
*alo7lika*

- [x] I have provided my GitHub ID.

---

#### Email ID
**Please mention your email ID for further communication.**  
*[email protected]*

- [x] I have provided my email ID.

---

#### Identify Yourself
**Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC,
SWOC).**
*Enter your participant role here.*GSSOC ext 24

- [x] I have mentioned my participant role.

---

#### Closes
**Enter the issue number that will be closed through this PR.**  
*Closes: #568 *

- [x] I have provided the issue number.

---

#### Describe the Add-ons or Changes You've Made
**Give a clear description of what you have added or modified.**  
*I have added an improved evaluation method for the model by
implementing new accuracy metrics and visualizations. The changes
include updating the model's evaluation function, adding
precision-recall curves, and modifying the code to output these
visualizations during testing.*

- [x] I have described my changes.

---

#### Type of Change
**Select the type of change:**  
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---

#### How Has This Been Tested?
**Describe how your changes have been tested.**  
*The changes have been tested by running the model with the updated
evaluation method on the validation dataset. Unit tests were created to
check for precision, recall, and F1-score calculations. Additionally,
visualizations were generated to verify that the output matches expected
behavior.*

- [x] I have described my testing process.

---

#### Checklist
**Please confirm the following:**  
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly wherever it was hard to
understand.
- [x] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] Any dependent changes have been merged and published in downstream
modules.
  • Loading branch information
UTSAVS26 authored Oct 16, 2024
2 parents d69ec90 + 6df9069 commit 8f77fe5
Show file tree
Hide file tree
Showing 2 changed files with 717 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# ๐Ÿšฆ Traffic Accident Prediction Model using Deep Learning

Welcome to the **Traffic Accident Prediction** project! This project utilizes machine learning techniques and historical data (e.g., accident records, weather conditions, traffic volume, road characteristics) to predict the likelihood of traffic accidents. Our aim is to provide insights into high-risk areas and conditions, enabling local authorities to implement targeted safety measures and improve traffic management strategies.

---

## ๐Ÿ“œ Table of Contents
- [Overview](#overview)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Dataset](#dataset)
- [Model Architecture](#model-architecture)
- [Evaluation](#evaluation)
- [Results](#results)
- [Future Improvements](#future-improvements)
- [Contributing](#contributing)
- [License](#license)

---

## ๐ŸŒŸ Overview
Traffic accidents can have severe consequences, both human and economic. This project aims to leverage deep learning to predict accident risks based on various features:
- ๐Ÿ“… **Date & Time**
- ๐ŸŒฆ๏ธ **Weather Conditions**
- ๐Ÿš— **Traffic Volume**
- ๐Ÿ›ฃ๏ธ **Road Characteristics**

By identifying high-risk situations, the model helps authorities and traffic planners reduce accident occurrences and improve public safety.

---

## โœจ Features
- โœ… **Accurate Predictions**: Provides reliable accident risk assessments based on multiple inputs.
- ๐Ÿ“Š **Data Visualization**: Visualizes accident patterns with charts and graphs for better insights.
- ๐Ÿšง **Model Evaluation**: Uses evaluation metrics like accuracy, precision, recall, and F1-score.
- ๐ŸŒ **Scalable**: Easily extendable to include more features like traffic camera data.

---

## โš™๏ธ Installation

To get started, clone this repository and install the required dependencies:

```bash
git clone https://github.com/alo7lika/traffic-accident-prediction.git
cd traffic-accident-prediction
pip install -r requirements.txt
```
Ensure you have Python 3.8+ installed along with the necessary libraries (e.g., `pandas`, `numpy`, `scikit-learn`, `tensorflow`).

---

## ๐Ÿš€ Usage

To run the model, follow these steps:

1. **Preprocess the Dataset**:
```bash
python preprocess_data.py
2. **Train the Model**:
```bash
python train_model.py
```
3. **Evaluate the Model**:
```bash
python evaluate_model.py
```
Make sure the dataset is correctly placed in the `data/` directory. You can adjust the hyperparameters in `config.yaml`.

---

## ๐Ÿ—ƒ๏ธ Dataset

| Feature | Description |
|-------------------|--------------------------------------|
| `date_time` | Date and time of the incident |
| `weather` | Weather conditions at the time |
| `traffic_volume` | Number of vehicles passing per hour |
| `road_type` | Type of road (highway, city road) |

The dataset is stored as a CSV file in the `data/` folder. If you have new data, update the file accordingly.

---

## ๐Ÿ—๏ธ Model Architecture

The model consists of a Convolutional Neural Network (CNN) and Long Short-Term Memory (LSTM) layers for feature extraction and time-series analysis. The architecture includes:

- **Input Layer**: Processes the input features (e.g., weather, traffic volume).
- **CNN Layers**: Extracts spatial features.
- **LSTM Layers**: Captures temporal dependencies.
- **Dense Layers**: Combines extracted features and outputs the prediction.

---

## ๐Ÿ“ˆ Evaluation

The modelโ€™s performance is evaluated using the following metrics:

| Metric | Description |
|-------------|--------------------------------------------------|
| **Accuracy**| The overall correctness of the model |
| **Precision**| Ratio of correctly predicted positive observations |
| **Recall** | Ratio of correctly predicted positive observations to the actual positives |
| **F1-Score**| Harmonic mean of precision and recall |

---

## ๐Ÿ“Š Results

The model achieved the following performance on the test dataset:

| Metric | Value |
|----------|-------|
| Accuracy | 92% |
| Precision| 89% |
| Recall | 90% |
| F1-Score | 89.5% |

You can visualize the model's predictions using the `visualize_results.py` script.
---
## ๐Ÿš€ Future Improvements
- ๐Ÿ”„ **Real-time data integration**: Incorporate live traffic and weather data for real-time accident risk assessment.
- ๐Ÿ›ฐ๏ธ **Satellite data**: Integrate satellite imagery for more precise road condition analysis.
- ๐Ÿง  **Model Optimization**: Fine-tune hyperparameters and try other neural network architectures.
---
## ๐Ÿค Contributing
Contributions are welcome! Follow these steps to contribute:
1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Commit your changes (`git commit -m "Add feature"`).
4. Push to the branch (`git push origin feature-branch`).
5. Open a Pull Request.
Please read the [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
---
## ๐Ÿ“„ License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
Loading

0 comments on commit 8f77fe5

Please sign in to comment.