NoCommentsElder
commited on
Commit
•
2f71b70
1
Parent(s):
8d134fc
Delete app.py
Browse files
app.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
!pip install seaborn
|
3 |
-
import seaborn as sns
|
4 |
-
sns.set(color_codes=True)
|
5 |
-
from sklearn.tree import DecisionTreeRegressor
|
6 |
-
import matplotlib.pyplot as plt
|
7 |
-
|
8 |
-
df = pd.read_csv('/input/us-accidents/US_Accidents_March23.csv')
|
9 |
-
from sklearn.linear_model import LinearRegression
|
10 |
-
|
11 |
-
import matplotlib.pyplot as plt
|
12 |
-
import seaborn as sns
|
13 |
-
import pandas as pd
|
14 |
-
|
15 |
-
# Convert 'Start_Time' to datetime format if not already
|
16 |
-
df['Start_Time'] = pd.to_datetime(df['Start_Time'], format='mixed')
|
17 |
-
|
18 |
-
|
19 |
-
# Create a 4x2 subplot grid
|
20 |
-
fig, axes = plt.subplots(4, 2, figsize=(18, 10))
|
21 |
-
plt.subplots_adjust(hspace=0.5) # Adjust horizontal space between plots
|
22 |
-
|
23 |
-
# Create a gradient blue color palette
|
24 |
-
n_colors = 8 # Number of colors needed
|
25 |
-
blue_palette = sns.light_palette("Red", n_colors=n_colors, reverse=True)
|
26 |
-
|
27 |
-
# Plot overall distribution and for each day of the week
|
28 |
-
for i in range(8):
|
29 |
-
ax = axes[i//2, i%2] # Determine the position of the subplot
|
30 |
-
|
31 |
-
if i == 0:
|
32 |
-
# Overall hourly accident distribution
|
33 |
-
sns.histplot(df['Start_Time'].dt.hour, bins=24, ax=ax, color=blue_palette[i])
|
34 |
-
ax.set_title("Overall Hourly Accident Distribution")
|
35 |
-
else:
|
36 |
-
# Hourly distribution for each day of the week
|
37 |
-
day_data = df[df['Start_Time'].dt.dayofweek == i-1]
|
38 |
-
sns.histplot(day_data['Start_Time'].dt.hour, bins=24, ax=ax, color=blue_palette[i])
|
39 |
-
ax.set_title(f"Hourly Accident Distribution: {day_data['Start_Time'].dt.day_name().iloc[0]}")
|
40 |
-
|
41 |
-
# Set x and y labels
|
42 |
-
ax.set_xlabel(f"Hour of {['Day', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'][i]}")
|
43 |
-
ax.set_ylabel("No. of Accidents")
|
44 |
-
|
45 |
-
plt.tight_layout()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|