Skip to content

Commit

Permalink
Merge pull request #629 from shivansh-2003/main
Browse files Browse the repository at this point in the history
[Feature Addition]: Web App for Vehicle Live Risk Prediction
  • Loading branch information
abhisheks008 authored Jun 11, 2024
2 parents 2f0aeb6 + 366e28e commit b5112ea
Show file tree
Hide file tree
Showing 15 changed files with 785 additions and 47 deletions.
37 changes: 37 additions & 0 deletions Vehicle Live Risk Prediction/Dataset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
noteId: "41f3da5024b711ef81150b8fd372c2c7"
tags: []

---

# Live Vehicle Risk Prediction Dataset

## Overview

The Live Vehicle Risk Prediction Dataset is a comprehensive collection of data points aimed at predicting the risk associated with vehicles in various driving conditions. The dataset includes information on visibility, road surface conditions, weather, traffic density, road hazards, driver fatigue, medical conditions, speeding, and light conditions, among others.

## Dataset Description

The dataset contains the following features:

- **Visibility**: Indicates the visibility level (e.g., Clear, Foggy, Rainy).
- **Road_Surface_Conditions**: Describes the state of the road surface (e.g., Dry, Wet, Icy).
- **Weather**: Weather conditions at the time of data collection (e.g., Sunny, Rainy, Snowy).
- **Traffic_Density**: Density of traffic (e.g., Low, Medium, High).
- **Road_Hazards**: Presence of any road hazards (e.g., None, Potholes, Debris).
- **Fatigue_Level**: Driver's level of fatigue (e.g., Low, Medium, High).
- **Medical_Condition**: Driver's medical condition (e.g., None, Mild, Severe).
- **Speeding**: Indicates if the vehicle was speeding (e.g., Yes, No).
- **Light_Conditions**: Lighting conditions during data collection (e.g., Daylight, Dusk, Night).

Additional columns may include:
- **Driver_Age**: Age of the driver.
- **Last_Service_Months_Ago**: Time since the vehicle was last serviced in months.

## Usage

This dataset can be used for building predictive models to assess vehicle risk under various conditions. It is suitable for machine learning applications such as classification and regression tasks aimed at improving vehicle safety and reducing accidents.




Binary file added Vehicle Live Risk Prediction/Images/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions Vehicle Live Risk Prediction/Model/ML-Crate.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"folders": [
{
"path": "../.."
},
{
"path": "../.."
},
{
"path": "../.."
},
{
"path": "../.."
},
{
"path": "../.."
}
]
}
100 changes: 100 additions & 0 deletions Vehicle Live Risk Prediction/Model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
noteId: "5336f36024b711ef81150b8fd372c2c7"
tags: []

---

# Live Vehicle Risk Detection using XGBoost Model

This project aims to predict vehicle risk scores using various environmental and driver-related factors. The model is trained using an XGBoost classifier and is capable of making real-time risk predictions based on the input data.

## Table of Contents

- [Project Description](#project-description)
- [Dataset](#dataset)
- [Usage](#usage)
- [Model Training](#model-training)
- [Evaluation](#evaluation)
- [Saving the Model](#saving-the-model)

## Project Description

The Live Vehicle Risk Detection project utilizes machine learning to predict the risk associated with a vehicle's current conditions. The model considers factors such as visibility, road surface conditions, weather, traffic density, road hazards, driver fatigue level, medical conditions, speeding, and light conditions to determine a risk score. The XGBoost model categorizes the risk as high or low based on a threshold value.

## Dataset

https://www.kaggle.com/datasets/punyamodi/vehicle-live-risk-prediction



## Usage

To use the vehicle risk detection model, follow these steps:

1. **Prepare the Dataset**:
Ensure the dataset is named `Vehicle Risk Prediction Dataset.csv` and placed in the project directory.

2. Make Predictions:
Once the model is trained, you can use the saved model to make predictions on new data. Load the model, encoders, and scaler from the vehicle_risk_model.pkl file and use them to transform and predict new data inputs.

## Model Training
### The training process involves several steps:

Load the Dataset:
The dataset is loaded from a CSV file using pandas.

Encode Categorical Features:
Categorical features are encoded using LabelEncoder to convert them into numerical values that can be used by the model.

Define Features and Target:
The features (X) include various environmental and driver-related factors. The target (y) is a binary classification based on the risk score (1 if the risk score is above 50, otherwise 0).

Split the Data:
The dataset is split into training and testing sets using train_test_split.

Standardize Features:
Feature values are standardized using StandardScaler to have a mean of 0 and a standard deviation of 1.

Train the Model:
An XGBoost classifier is created and trained on the scaled training data.


## Evaluation
After training the model, its performance is evaluated on the test set:

Make Predictions:
The model makes predictions on the scaled test data.

Calculate Accuracy:
The accuracy of the model is computed to determine how well the model predicts the correct class.

Classification Report:
A detailed classification report is generated, which includes precision, recall, and F1 scores for both classes (high risk and low risk).

## Saving the Model
After training and evaluating the model, the following components are saved to a single file named vehicle_risk_model.pkl using joblib:

## Model used in this Project
1) Decision Tree
2) Random Forest
3) ANN
4) Multivariate Logisitic Regression
5) Lasso
6) Gradient Boost
7) Ridge
8) MLP
9) XGBoost

### Models and Accuracies

| Model | Accuracy | MSE SCORE |
| ----------------------------- |:----------:| ------------------:|
| Decision Tree | 0.9996 | |
| Random Forest | 1.0 | |
| ANN | 1.0 | |
| Logistic Regression | 1.0 | |
| Lasso | N.A | 0.03247239784420999|
| Gradient Boost | 1.0 | |
| Ridge | N.A | 0.007214250517408194|
| MLP | 0.9997 | |
| XGBoost | 1.0 | |
416 changes: 371 additions & 45 deletions Vehicle Live Risk Prediction/Model/Xgboost.ipynb

Large diffs are not rendered by default.

Binary file not shown.
33 changes: 31 additions & 2 deletions Vehicle Live Risk Prediction/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
**VEHICLE LIVE RISK PREDICTION MODEL**


### Overview
The Vehicle Risk Prediction application is designed to predict the risk associated with driving a vehicle based on various factors such as weather conditions, road hazards, visibility, traffic density, and driver-related factors like fatigue level, speeding, and medical conditions. The application utilizes a machine learning model trained on historical data to provide risk predictions.



**GOAL**

To build a machine learning model for predicting the risk of accident or not.
'The aim is to create a web app for the Vehicle Live Risk Prediction project. Use the best existing model in the project folder. Follow the Web App README template for the same.'


**DATASET**

Expand Down Expand Up @@ -72,6 +79,7 @@ These sample images show relationship of columns with each other(more detail in
5) SEABORN
6) SCIKIT-LEARN
7) XGBOOST
8) streamlit

**IMPLEMENTATION**
1) Loaded the dataset with 20 columns having 15000 entries.
Expand Down Expand Up @@ -107,6 +115,27 @@ These sample images show relationship of columns with each other(more detail in


...
### Model(s) used for the Web App
XGBoost (Extreme Gradient Boosting) is a powerful and widely-used machine learning algorithm known for its efficiency and effectiveness in predictive modeling tasks. It belongs to the ensemble learning methods, specifically boosting algorithms, and has gained popularity for its exceptional performance in various machine learning competitions and real-world applications.

#### Install Requirements
While the virtual environment is activated, install the required packages using pip:
```
pip install -r requirements.txt
```
#### Run the Application
After installing the requirements, run the Streamlit application using the following command:
```
streamlit run app.py
```




### Signature ✒️

Name:-Shivansh Mahajan

Github:-https://github.com/shivansh-2003

**NAME**
Keshav Arora
Linkedin:-https://www.linkedin.com/in/shivansh-mahajan-13227824a/
59 changes: 59 additions & 0 deletions Vehicle Live Risk Prediction/Web App/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

## [Feature Addition]: Web App for Vehicle Live Risk Prediction #602
![Visual Overview](https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExdzdqZjlmZXZnODI0YTJyd2NmNGdkZmRndnk0MDY0ZjN1MDNjZmYxeSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/gKBRsM4xJJS2GhAQij/giphy-downsized-large.gif)

### Overview
The Vehicle Risk Prediction application is designed to predict the risk associated with driving a vehicle based on various factors such as weather conditions, road hazards, visibility, traffic density, and driver-related factors like fatigue level, speeding, and medical conditions. The application utilizes a machine learning model trained on historical data to provide risk predictions.


### Goal 🎯
'The aim is to create a web app for the Vehicle Live Risk Prediction project. Use the best existing model in the project folder. Follow the Web App README template for the same.'


### Functionality
#### Main Model Page:
- **Input Fields:** Users can enter details such as Visibility, Road Surface Conditions, Weather, Traffic Density, Road Hazards, Fatigue Level, Medical Condition, Speeding, and Light Condition.
- **Prediction:** After entering the required information and clicking on the "Predict Risk" button, the application calculates the risk level (High Risk or Low Risk) based on the user's input.

#### Visualization Page:
- **Data Overview:** Displays the first few rows of the dataset and provides an overview of the data.
- **Data Statistics:** Shows summary statistics of numerical columns in the dataset.
- **Correlation Heatmap:** Visualizes the correlation between numerical features using a heatmap.
- **Countplots of Categorical Features:** Displays count plots for each categorical feature in the dataset.


#### About Page:
- **Model Explanation (XGBoost):** Provides an explanation of the machine learning model used in the application, focusing on the XGBoost (Extreme Gradient Boosting) algorithm.
- **Purpose:** Explains the purpose and goal of the Vehicle Risk Prediction application.

## Technology Stack
The Vehicle Risk Prediction application is built using the following technologies:
- **Streamlit:** Used for building the user interface and web application.
- **Pandas:** Used for data manipulation and handling input data.
- **Joblib:** Used for loading the machine learning model, encoders, and scaler.
- **XGBoost:** Machine learning algorithm used for risk prediction.

## How to Use
1. **Navigation:** Use the sidebar to navigate between the Main Model Page, Visualization Page, and About Page.
2. **Main Model Page:**
- Fill in all required fields with relevant information.
- Click on the "Predict Risk" button to see the risk prediction.
3. **Visualization Page:**
- Explore data overview, statistics, correlations, countplots, and pairplots to gain insights into the dataset.
4. **About Page:**
- Provides information about the model explanation and purpose of the application.

### Video Demonstration 🎥
[Watch the video](https://vimeo.com/953208773?share=copy)



https://github.com/shivansh-2003/ML-Crate/assets/144326194/d8b87a5f-0f80-477f-877c-0d60df781289

### Signature ✒️

Name:-Shivansh Mahajan

Github:-https://github.com/shivansh-2003

Linkedin:-https://www.linkedin.com/in/shivansh-mahajan-13227824a/
Binary file not shown.
Loading

0 comments on commit b5112ea

Please sign in to comment.