Skip to main content

Chicago Vanguard

A large-scale crime pattern analysis project using Apache Spark, distributed analytics, Spark SQL, and KMeans clustering.

  • Big Data Analytics
  • Apache Spark
  • Data Engineering
  • Machine Learning
  • Data Visualization
Chicago Vanguard crime analytics project cover with a Chicago map and data visualizations.

Project overview

Chicago Vanguard analyzes large-scale public crime data to reveal spatial, temporal, and behavioral patterns across Chicago. The project transforms millions of raw records into structured insights using Apache Spark.

The workflow combines scalable preprocessing, RDD transformations, Spark SQL queries, feature engineering, and unsupervised machine learning to identify hotspots and discover hidden crime groupings.

8.5M+Original crime records
22Raw dataset columns
419,883Processed sample rows
25Final analysis columns

The challenge

The original dataset contains more than eight million incidents collected across many years. Traditional single-machine processing becomes slow and difficult to scale at this volume.

Missing coordinates, invalid timestamps, duplicate IDs, inconsistent text, and geographic outliers also needed to be resolved before the data could support reliable analytics or clustering.

Analysis pipeline

The complete workflow was designed as a clear sequence from raw CSV ingestion to clustering evaluation. Every stage prepares the dataset for the next while preserving reproducibility.

01Raw CSV data8,505,782 rows · 22 columns
02Clean and reduceNulls · duplicates · sampling · validation
03Engineer featuresSpatial · temporal · behavioral context
04VectorAssemblerCombine five numerical features
05StandardScalerNormalize feature magnitudes
06KMeansTrain models for k = 2 to 6
07EvaluationSilhouette score and cluster analysis

Understanding the data

The selected schema combines categorical, numerical, geographic, temporal, and Boolean attributes. Together, these fields support both hotspot detection and time-based crime analysis.

FeatureTypeAnalytical purpose
Primary TypeCategoricalCrime category analysis
DistrictNumericDistrict-level hotspot detection
Community AreaNumericLocal spatial aggregation
DateTimestampHour, weekday, and month extraction
Latitude / LongitudeNumericGeographic clustering
Arrest / DomesticBooleanContextual crime indicators

Preprocessing at scale

Critical null records were removed, descriptive fields were filled with UNKNOWN, duplicate incidents were eliminated by ID, and dates were converted into valid timestamps.

Coordinates outside Chicago boundaries were filtered, text values were trimmed and standardized, and extreme geographic values were capped before a reproducible 5% sample was created.

01

Clean

Null handling, deduplication, timestamp validation

02

Reduce

5% seeded sample and focused feature selection

03

Transform

Type casting, indexing, encoding, and scaling

04

Validate

Coordinate boundaries and outlier treatment

Feature engineering

New features converted raw timestamps and locations into more useful indicators. These additions allowed the analysis to compare periods, recognize hotspot behavior, and give the clustering model richer context.

TemporalHour, Weekday, Month
BehavioralIs_Weekend, Is_Night, Time_Of_Day
SpatialDistrict_Community_Key, Is_Hotspot_Location
StatisticalLocation_Crime_Count, PrimaryType_ArrestRate
ML outputfeatures_vec, features_scaled

Distributed RDD analysis

The transformed data was converted into Resilient Distributed Datasets. Operations such as map, filter, reduceByKey, and sortBy produced frequency-based and temporal summaries across partitions.

RDD frequency analysisScala · Apache Spark
val crimeCounts = rdd
  .map(row => (row.primaryType, 1))
  .reduceByKey(_ + _)
  .sortBy(_._2, ascending = false)
Spatial

Hotspot districts

District-level aggregation exposed areas with consistently higher incident activity.

Categorical

Common crime types

Primary Type grouping ranked the most frequently reported crime categories.

Temporal

Hour and weekday patterns

Time-based features revealed meaningful variation across hours and days.

Spark SQL analytics

A temporary SQL view made large-scale filtering, grouping, ranking, and aggregation easier to interpret. Advanced queries also used CTEs, subqueries, and window functions.

Top crime categoriesSpark SQL
SELECT Primary_Type, COUNT(*) AS Crime_Count
FROM crime_data
GROUP BY Primary_Type
ORDER BY Crime_Count DESC
LIMIT 10;

KMeans model selection

Five numerical features were assembled and standardized before an 80/20 train-test split. Models from k = 2 through k = 6 were compared using the silhouette score.

The final model used k = 5 because it produced the strongest score, improving separation over the k = 2 baseline while maintaining balanced, non-empty clusters.

Selected modelk = 5
Best silhouette0.3467
k = 2
0.3304
k = 3
0.3123
k = 4
0.3217
k = 5
0.3467
k = 6
0.3235

Technology stack

Apache Spark provided distributed processing through DataFrames, RDDs, Spark SQL, and MLlib. Scala supported Spark transformations and analytical logic, while CSV-based outputs preserved the processed data.

Apache SparkSpark SQLSpark MLlibScalaKMeansDataFramesRDDsCSV

Project outcome

Chicago Vanguard demonstrates an end-to-end big data workflow that converts a noisy public dataset into scalable, interpretable crime analytics and behavioral clusters.

The result supports hotspot exploration and pattern discovery without claiming to predict individual incidents. Future work could add social context and compare KMeans with DBSCAN or Gaussian Mixture Models.