- Youssef Kandil
- Mahmoud Khaled
- Youssef Alaa
- Ziad Abdelwahab
This project builds a reproducible big data pipeline for a raw crime dataset. The pipeline starts from a CSV file, performs preprocessing, generates textual insights, creates summary visualizations, and applies K-Means clustering.
The generated outputs are:
data_raw.csvdata_preprocessed.csvinsight1.txtinsight2.txtinsight3.txtsummary_plot.pngclusters.txt
crime-analysis/
├── Dockerfile
├── ingest.py
├── preprocess.py
├── analytics.py
├── visualize.py
├── cluster.py
├── summary.sh
├── README.md
└── results/
- Python 3.11
- pandas
- numpy
- matplotlib
- seaborn
- scikit-learn
- scipy
- requests
- Docker
Use the following commands to build and run the container:
docker build -t crime-analysis .
docker run -it --name crime-analysis-run crime-analysisDo not use --rm here, because summary.sh needs the container to still exist in order to copy the output files.
The intended pipeline flow is:
ingest.py -> preprocess.py -> analytics.py -> visualize.py -> cluster.py
The execution order used for this project is:
ingest.pyreads the raw dataset path from the command line and saves a copy asdata_raw.csv.preprocess.pyloads the latest CSV file, removes unnecessary columns, fills missing values, removes duplicates, extracts time features, and encodes grouped categorical values.analytics.pygenerates textual insights and saves them asinsight1.txt,insight2.txt, andinsight3.txt. In the current codebase,preprocess.pyalready callsanalytics.pyautomatically.visualize.pygenerates a summary figure containing the distribution of crimes by hour, incident counts by month, and a correlation heatmap.cluster.pyapplies K-Means clustering on numeric features and writes the cluster output toclusters.txt.summary.shcopies all.csv,.txt, and.pngoutputs from the container to the hostresults/directory, then stops and removes the container.
After opening the container shell, run the pipeline in this order:
python ingest.py <path_to_raw_dataset.csv>
python preprocess.py data_raw.csv
python visualize.py data_preprocessed.csv
python cluster.pyThen, on the host machine:
chmod +x summary.sh
./summary.sh crime-analysis-rundata_raw.csv: exact copy of the input datasetdata_preprocessed.csv: cleaned and transformed dataset used by the later stages
The current generated insights are:
insight1.txt
The most frequent crime in the dataset is THEFT, with 10,780 incidents out of 52,025 total records (20.72%). The second most common category is BATTERY with 8,997 incidents (17.29%).
insight2.txt
Public locations contain the largest share of incidents, with 20,086 records (38.61%). The busiest hour is 12:00, when 3,053 incidents were recorded. Friday is the peak day with 8,379 incidents (16.11%).
insight3.txt
The overall arrest rate in the dataset is 28.23%. Among crime categories with at least 500 incidents, PROSTITUTION has the highest arrest rate at 100.00% across 560 cases.
The file summary_plot.png contains the three required plots in one summary image.
clusters.txt contains the K-Means clustering output. Example excerpt:
Top features for Cluster 0:
Year 2009.164276
Beat 383.263083
Latitude 41.768830
Community Area 37.981949
Ward 24.798343
Hour 13.230013
Month 5.378595
District 3.617633
The summary.sh script:
- copies all generated
.csv,.txt, and.pngfiles from/app/pipeline/ - saves them into
results/on the host - stops the running container
- removes the container afterward
- The pipeline is designed to run inside a Docker container based on
python:3.11-slim. - The dataset should be raw and not pre-cleaned, as required in the assignment instructions.
- All outputs can be regenerated by running the same containerized workflow again.
- Ensure the final
crime-analysis/folder matches the required assignment structure - Ensure
results/contains the generated.csv,.txt, and.pngfiles - Include this README inside the final
crime-analysis/folder - Verify all team members understand each stage of the pipeline before the discussion
