Seattle Traffic Data-Analysis and Risk Prediction(IBM Capstone Project)
By: Pu Misra
Tags: Coursera Capstone, Data Science, Predictive Analytics, Ibm Watson, Machine Learning

SEATTLE TRAFFICK DATA ANALYSIS AND RISK PREDICTION

IBM Final Capstone Project

Puja Misra (10th Oct 2020)

1.Introduction

This project is our Final submission to IBM Data Science Professional Certificate course on Coursera. The goal of the project is to detail and use Data Science tool set for Predictive analysis.

We will be working on a real-life problem and demonstrate how Machine Learning can help us predict and process the value by applying the learned skills.

2.Business Understanding

2.1 Background:

According to 2017 WSDOT data, a car accident occurs every 4 minutes and a person dies due to a car crash every 20 hours. Fatal crashes went from 508 in 2016 to 525 in 2017, resulting in the death of 555 people. This number has stayed relatively steady for the past decade. According to 2017 WSDOT data, a car accident occurs every 4 minutes and a person dies due to a car crash every 20 hours. Fatal crashes went from 508 in 2016 to 525 in 2017, resulting in the death of 555 people. This number has stayed relatively steady for the past decade.

2.2 Problem Statement:

As we see in the background statement above, the numbers of fatal crashes are having an upward trend or has been steady for past decade for Seattle as per WSDOT.

2.3 Objective of the Project:

The purpose of the project is to gather the data and determine what causes the accident and the attributes that leads to the severity.

Through data visualization and machine learning algorithm we will be analyzing a significant range of attributes, including weather conditions, road condition, speeding, special events, roadworks, traffic jams among others and we will try to predict what are the conditions that can contribute to high severity accidents which may cause loss of life or loss of property .WSOT can use the model to take precaution to minimize the loss of property and life.

Reducing the insurance cost and Preventing fatalities

2.4 Stakeholders:

Government Officials

Emergency Responders (911 dispatchers)

Common People

Insurance Companies

2.5.Data understanding

We chose the public data from open source available with labeled columns and attributes and observations data to help us do our analysis better.

Sample Data Below

Link to the Data

https://s3.us.cloud-object-storage.appdomain.cloud/cf-courses-data/CognitiveClass/DP0701EN/version-2/Data-Collisions.csv

https://www.seattle.gov/Documents/Departments/SDOT/GIS/Collisions_OD.pdf

The data consists of 40 independent variables and 221738 rows. The dependent variable, “SEVERITYCODE”, contains numbers that correspond to different levels of severity caused by an accident from 0 to 4.

Severity codes are as follows: 0: Unknown 1: Property Damage 2: Injury 2b: Serious Injury 3: Fatality 4.Data Preparation 2.6 Public Traffic data for Seattle city USA is available from the Open source (Link Mentioned above) 2.7 After the data has been extracted, keeping the columns required in the data frame. 2.8 Excluding the rows with null values. 2.9 Transform the data type for analysis. 3.0 Load Data to the Data frame.

Original Size of the Data frame

Missing Values from the Data frame

Preparing the Data after doing the Data Cleansing

Data Cleansing-Dropping the unwanted columns.

Casting the columns to right datatype (numerical variables) for calculations.

Count Based on the Road Condition

5.Exploratory Data Analysis

We will run a value count on road (‘ROADCOND’) and weather condition (‘WEATHER’) to get ideas of the different road and weather conditions. We will also check the value count on light condition (’LIGHTCOND’), to see the breakdowns of accidents occurring during the different light conditions. The results will then be used for data modeling.

5.1 SEVERITY CODE count

5.2 ROADCOND count

5.3 WEATHER count

5.4 LIGHTCOND count

Graphs built with seaborn library below to check how the severity is impacted by various attributes.

OBSERVATIONS:

1.1 Number of pedestrians involved in the collision (PEDCOUNT) and Severity

1.2 Severity 2 (Injury) accidents has happened to Pedestrians, compared to SERV 1 accidents

1.3 Number of people involved in the collision (PERSONCOUNT) and Severity¶

1.4 The data shows that the severity of the accident is high with person count.

1.5 The below data shows accidents are happening more near the blocks and less at intersection. Severity 2 is almost same on block and on Intersection

1.6 Number of cases of accidents when car was parked

1.7 Looking at the Speeding cases, there were 9381 speeding cases.

1.8 Figure shows the high number of accidents when people were under influence.

For further analysis we created an Incident dataset.

Following features were used: “Incident Date”, “Incident Time”, “Collision Time”, “Collision condition”, “Light Condition” indicating the Incident Detail.

Incident Dataset

1.9 The Below graph shows the daily accidents from 2013 till 2020 with high around end of 2016 and beginning of 2017 and the number of accidents low in 2020.

Plotting the accidents Per year, confirms the same trend as above

6.Modeling

6.1 Using NumPy, Scalar, Linear regression on the clean transformed data /Shown Above)

6.2 After importing necessary packages and splitting preprocessed data into test and train sets, for each machine learning model, we will build and evaluate the model with the techniques as follow:

6.3 Data frame with features below created [“ADDRTYPE”,” COLLISIONTYPE,” JUNCTIONTYPE”,” WEATHER”,” ROADCOND”,” LIGHTCOND”,” UNDERINFL”,” HITPARKEDCAR”]

Heatmap

7. Machine Learning Models

7.1 GitHub as a repository and running Jupiter Notebook are used to process data and build Machine Learning models

7.2 Python and its popular packages such as Pandas, NumPy and Sklearn are used for determining the accuracy.

7.3 The dataset x and y are constructed. After normalization they are split into x_train,y_train,x_test and y_test using train_test split.75% of the data is used for training and 25% is used for testing as below

K Nearest Neighbor (KNN)

· LINEAR REGRESSION

· DECISION TREE

Based on the data sample of train and test data we see there is an Overfitting, meaning our model is learning the noise from the data and its ability to generalize the results is very low. In this case you have a small training error but very large validation error. So, we will try to prune the data set and run the model again.

We changed our dataset and started again to find the accuracy and which model fits the best.

Data frame:data_clean

Data_Clean

· DECISION TREE

Accuracy Score :0.63

· LINEAR REGRESSION

Accuracy Score: 0.72

· RANDOM FOREST

Accuracy Score:0.73

· KNN

Accuracy Score:0.72

8.CONCLUSION

With the help of machine learning algorithms we were able to predict the impact of weather, road condition and light condition on the seriousness of the accidents .Property damage (class 1) or injury (class 2) with graphs.

From the Machine Learning model we saw except Decision Tree the other three models have a close accuracy of 72–73% which means that the model has trained well.

KNN, Logistic Regression, Random forest have an accuracy of 72–74%, this is because of the similarity of the features for both types of accidents (1 and 2)

Though with 73% of accuracy from Random Forest we can say that the model has trained well and performs well on the testing as well as the trained data.

The model is ready to be used.

9. FUTURE DIRECTIONS

There is more scope of improvement in terms of accuracy by adding additional features in the data set and by having fewer null values and more data for speeding and other important columns (like attention id, under influence and collision type). Missing Data List shown below.

Thanks For Reading. Appreciate your Feedback if any.