-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,637 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Traffic-Accident-Analysis |
1,474 changes: 1,474 additions & 0 deletions
1,474
Traffic accidents by time of occurrence 2001-2014.csv
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
library(party) | ||
print(head(readingSkills)) | ||
dataset<-read.csv("Data_Final.csv") | ||
|
||
high=ifelse(dataset$SEVERITY>=2,"MODERATE","HIGH") | ||
check=ifelse(dataset$SEVERITY>=2,"HIGH","MODERATE") | ||
|
||
dataset=data.frame(dataset,high) | ||
dataset=data.frame(dataset,check) | ||
|
||
input.dat <- dataset[c(1:10000),] | ||
png(file = "decision_tree_example9.png") | ||
|
||
#dataset = dataset[,-31] | ||
names(dataset) | ||
output.tree <- ctree(high ~ DAY_OF_WEEK + LIGHT_CONDITION, data = input.dat) | ||
plot(output.tree) | ||
dev.off() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
import seaborn as sns | ||
# Importing the dataset | ||
dataset = pd.read_csv('Data_Final.csv') | ||
X = dataset.iloc[:,:].values | ||
X = np.delete(X,2,axis=1) | ||
X = np.delete(X,1,axis=1) | ||
X = np.delete(X,0,axis=1) | ||
names = (dataset.columns.values) | ||
names = names[3:] | ||
|
||
from sklearn.preprocessing import Imputer | ||
imputer = Imputer(missing_values='NaN',strategy="most_frequent",axis=0) | ||
imputer = imputer.fit(X[:,:]) | ||
X[:,:] = imputer.transform(X[:,:]) | ||
data_new = pd.DataFrame(data=X,columns=names) | ||
|
||
imputer = Imputer(missing_values=-1,strategy="most_frequent",axis=0) | ||
imputer = imputer.fit(X[:,:]) | ||
X[:,:] = imputer.transform(X[:,:]) | ||
data_new = pd.DataFrame(data=X,columns=names) | ||
|
||
|
||
|
||
plt.figure(figsize=(30,8)) | ||
|
||
sns.countplot(x='LIGHT_CONDITION', hue='SEVERITY',data=data_new) | ||
sns.countplot(x='SEVERITY',hue='ALCOHOLTIME',data=data_new) | ||
sns.countplot(x='LIGHT_CONDITION',hue='ALCOHOLTIME',data=data_new) | ||
sns.countplot(x='SEVERITY',hue='SPEED_ZONE',data=data_new) | ||
sns.countplot(x='POLICE_ATTEND',hue='SPEED_ZONE',data=data_new) | ||
sns.countplot(x='FEMALES',hue='SEVERITY',data=data_new) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue May 1 17:40:46 2018 | ||
@author: Prashant | ||
""" | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
dataset = pd.read_csv("Accidents0515.csv") | ||
|
||
|
||
time1=dataset['Time'] | ||
time=dataset['Time'].values | ||
|
||
t=[] | ||
j=0 | ||
for i in time: | ||
t.append((i)) | ||
j+=1 | ||
x = [] | ||
for i in range(len(t)): | ||
s = t[i] | ||
x.append(s[0:2]) | ||
import math | ||
j=0 | ||
for i in x: | ||
x[j] = math.ceil(int(i)/3) | ||
j+=1 | ||
|
||
accident_time = {} | ||
for i in x: | ||
if i in accident_time: | ||
accident_time[i]+=1 | ||
else: | ||
accident_time[i]=1 | ||
accident_time[1]+=accident_time[0] | ||
del(accident_time[0]) | ||
|
||
val=[] | ||
for i in sorted(accident_time): | ||
val.append(accident_time[i]) | ||
|
||
plt.figure(figsize=(10,5)) | ||
label = ['12am-3am','3am-6am','6am-9am','9am-12pm','12pm-3pm','3pm-6pm','6pm-9pm','9pm-12am'] | ||
plt.bar(list(accident_time.keys()),accident_time.values()) | ||
plt.xticks([1,2,3,4,5,6,7,8],label) | ||
plt.xlabel('Time (3-hour period)') | ||
plt.ylabel('Total deaths') | ||
|
||
|
||
day_of_week = dataset['Day_of_Week'].values | ||
day_freq = {} | ||
for i in day_of_week: | ||
if(math.isnan(i)): | ||
pass | ||
elif int(i) not in day_freq: | ||
day_freq[int(i)]=1 | ||
else: | ||
day_freq[int(i)]+=1 | ||
|
||
labels = 'Monday', 'Tuesday', 'Wednesday', 'Thursday','Friday','Saturday','Sunday' | ||
sizes = [day_freq[1],day_freq[2],day_freq[3],day_freq[4],day_freq[5],day_freq[6],day_freq[7]] | ||
fig1, ax1 = plt.subplots() | ||
ax1.pie(sizes, labels=labels, autopct='%1.1f%%', | ||
shadow=True, startangle=90) | ||
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle. | ||
|
||
plt.show() | ||
|
||
|
||
#for i in X: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Tue May 1 10:59:30 2018 | ||
@author: Prashant | ||
""" | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
import seaborn as sns | ||
|
||
data = pd.read_csv('Traffic accidents by time of occurrence 2001-2014.csv') | ||
X = data.iloc[18,:].values | ||
|
||
accident_time = {1:X[3],2:X[4],3:X[5],4:X[6],5:X[7],6:X[8],7:X[9],8:X[10]} | ||
times = list(accident_time.keys()) | ||
label = ['0-3Hrs','3-6Hrs','6-9Hrs','9-12Hrs','12-15Hrs','15-18Hrs','18-21Hrs','21-24Hrs'] | ||
#no_of_accidents1 = [X[3],X[4],X[5],X[6],X[7],X[8],X[9],X[10]] | ||
#no_of_accidents = list(accident_time.values()) | ||
plt.figure(figsize=(30,8)) | ||
#plt.bar(times,no_of_accidents) | ||
|
||
|
||
val=[] | ||
for i in sorted(accident_time): | ||
val.append(accident_time[i]) | ||
|
||
plt.figure(figsize=(10,5)) | ||
|
||
plt.bar(list(accident_time.keys()),accident_time.values()) | ||
plt.xticks([1,2,3,4,5,6,7,8],label) | ||
plt.xlabel('Time (3-hour period)') | ||
plt.ylabel('Total deaths') |