Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PRODIGY_DS_05

Data Science Internship — Task 5 · Prodigy InfoTech

📌 Task

Analyze traffic accident data to identify patterns related to road conditions, weather, and time of day. Visualize accident hotspots and contributing factors.

📊 Dataset

US Accidents dataset (Kaggle, by Sobhan Moosavi) — used in the Prodigy-InfoTech/data-science-datasets repository for this task. A countrywide car accident dataset covering multiple US states, with location, time, weather, and nearby road-infrastructure data for each recorded accident.

Key columns used:

Column Description
Severity Accident severity (1 = least, 4 = most impactful)
Start_Time Timestamp of the accident
Start_Lat, Start_Lng Location coordinates
City, State Location
Temperature(F), Humidity(%), Visibility(mi), Wind_Speed(mph), Precipitation(in) Weather readings
Weather_Condition Weather description (Clear, Rain, Fog, Snow, etc.)
Crossing, Junction, Traffic_Signal, Station, Stop, Bump Boolean flags — nearby road/POI features
Sunrise_Sunset Day or Night at the time of the accident

Note: us_accidents.csv here is a synthetic dataset built to match the real dataset's structure and general patterns (rush-hour peaks, weather-driven visibility effects, city-level clustering). Swap in the real file before final submission — no code changes needed, since column names match exactly. The real dataset is very large (millions of rows); for local development, Kaggle also offers smaller pre-filtered subsets.

🛠️ Tech Stack

  • Python 3
  • pandas, numpy — data loading & cleaning
  • matplotlib, seaborn — visualization

📁 Repository Structure

PRODIGY_DS_05/
├── generate_sample_data.py              # creates the sample us_accidents.csv
├── us_accidents.csv                     # dataset (swap with the real file)
├── traffic_accident_analysis.py         # full cleaning + EDA + hotspot analysis
├── 01_accidents_by_hour.png … 12_hour_weather_heatmap.png   # generated charts
└── README.md

▶️ How to Run

pip install pandas numpy matplotlib seaborn

# (optional) regenerate the sample dataset
python generate_sample_data.py

# run the full analysis
python traffic_accident_analysis.py

Structured with # %% cell markers — runs cell-by-cell in VS Code (with the Jupyter extension) or in a Jupyter notebook, or top-to-bottom as a plain script.

🧹 Data Cleaning Steps

  • Dropped rows missing core fields (location, time, severity) that can't be meaningfully imputed
  • Filled missing weather readings with the column median
  • Filled missing Weather_Condition with "Unknown" rather than dropping
  • Removed duplicate rows
  • Engineered time features from Start_Time: Hour, DayOfWeek, Month, IsWeekend

📈 Analysis Performed

  • Time of day: accident counts by hour, by day of week, day vs night
  • Weather: accident counts by weather condition, visibility vs severity, correlation between weather variables and severity
  • Road conditions/infrastructure: presence rate of nearby features (crossings, junctions, traffic signals, etc.), average severity when each feature is present
  • Hotspots: scatter map of accident locations colored by severity, top 10 cities by accident count, hexbin density heatmap
  • Combined pattern: hour-of-day × weather-condition heatmap

💡 Key Insights

  • Accidents peak during rush hours, especially the evening commute, and are more frequent on weekdays than weekends — consistent with commute-driven traffic volume.
  • Most accidents by raw count occur in clear/fair weather simply because that's when most driving happens — but low-visibility conditions (fog, heavy rain, snow) are associated with higher average severity per accident, a distinction that raw counts alone would miss.
  • Traffic signals and crossings are the most common nearby road features at accident sites, reflecting both elevated conflict points and their concentration in dense urban traffic.
  • Accidents cluster heavily in a small number of dense metro areas rather than being evenly spread — hotspot mapping makes this concentration visible in a way that summary statistics alone do not.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages