Skip to content

Commit

Permalink
Merge pull request #930 from alo7lika/main
Browse files Browse the repository at this point in the history
Traffic Accident Prediction Model using Deep Learning
  • Loading branch information
abhisheks008 authored Oct 26, 2024
2 parents cd120d1 + f77e80e commit c5ccc15
Show file tree
Hide file tree
Showing 8 changed files with 765 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Dataset Overview

The project uses a synthetic dataset to simulate traffic accident occurrences based on several conditions over a one-year period (365 days). This data is intended to train a deep learning model, specifically an LSTM, for predicting accidents based on historical trends.

## Dataset Structure

The dataset includes the following features:

| Feature | Description | Type |
|----------------------|----------------------------------------------------------------------------------------------|-----------|
| **Date** | A sequence of dates over one year, used as the time basis for other data. | Date |
| **Traffic Volume** | Simulated daily traffic volume, with random values within a range (e.g., 100 to 2000). | Integer |
| **Weather Condition**| Categorical data representing different weather scenarios, including `clear`, `rain`, `fog`, and `snow`. | Categorical |
| **Road Type** | Categorical data representing types of roads, such as `highway`, `urban road`, and `rural road`. | Categorical |
| **Accident Occurred**| Binary indicator of whether an accident occurred on a given day, based on traffic and weather conditions. | Binary |

## Accident Occurrence Simulation

The likelihood of an accident is influenced by:

- **Weather Conditions**: Higher chance of accidents under `rain`, `fog`, or `snow`.
- **Traffic Volume**: Accidents become more likely with increased traffic volume, particularly above 1500 vehicles per day.

For example:
- A 30% chance of an accident occurs when traffic is high and the weather is adverse.
- A lower, 5% base chance is assigned for normal conditions.

## Example Dataset (First 5 Rows)

| Date | Traffic Volume | Weather Condition | Road Type | Accident Occurred |
|------------|----------------|-------------------|--------------|--------------------|
| 2023-01-01 | 1500 | Clear | Urban road | 0 |
| 2023-01-02 | 1800 | Rain | Highway | 1 |
| 2023-01-03 | 1300 | Fog | Rural road | 0 |
| 2023-01-04 | 1900 | Snow | Highway | 1 |
| 2023-01-05 | 1200 | Clear | Urban road | 0 |

This structured data is used to train the LSTM model for predicting accident probabilities, with categorical features encoded and normalized for model readiness.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
149 changes: 149 additions & 0 deletions Traffic Accident Prediction Model using Deep Learning /Model/README.md
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 c5ccc15

Please sign in to comment.