This repository contains my full machine-learning pipeline for analyzing and modeling the Crime in Los Angeles dataset.
The work includes data exploration, feature engineering, unsupervised learning, regression, classification, and deployment of the final model.
The goal of this project was to predict and classify crime characteristics using data from the Los Angeles crime dataset.
I built a full ML workflow—from EDA to modeling—to understand what affects crime timing and to create practical prediction models.
Business goal:
Model crime behavior to uncover patterns and build a classifier that can categorize crime events into meaningful groups.
Dataset Overview-
The dataset includes more than 1.4M crime records from Los Angeles, containing fields such as:
• Crime type
• Location & area
• Victim demographics
• Time and date
• Weapon & premise details
The target for the regression task was:
crime_time_minutes – the time of occurrence converted into minutes since midnight.
Main Research Question-
“Can crime characteristics predict the time of day a crime occurs in Los Angeles?”
I convert the crime time (HHMM format) into minutes since midnight to use it as a numeric regression target.
Research Sub-Questions-
To deepen the analysis and better understand crime patterns in Los Angeles, I defined four supporting research questions:
1. Which demographic factors (such as victim age or sex) are most associated with different crime times during the day?
2. How does crime behavior vary across geographic areas within Los Angeles? Are certain areas more active at specific hours?
3. Do temporal patterns—such as day of week, weekend vs. weekday, or season—meaningfully influence when crimes occur?
4. Can unsupervised learning (K-Means clustering) reveal hidden behavioral groups of crime events that are not visible from the raw features alone?
These questions guided the feature engineering, modeling strategy, and interpretation of the results throughout the project.
Key Features Used in the Project-
The project relies on a combination of original and engineered features that capture temporal, behavioral, and contextual aspects of crime events in Los Angeles.
Original Features
• Crime Code – categorical identifier of the crime type
• Area ID – geographic region of the incident
• Victim Age – numeric
• Date Occurred – raw date field
• Time Occurred – raw time field (HHMM format)
Exploratory Data Analysis (EDA)-
Key steps performed:
• Cleaning missing values
• Parsing and converting dates
• Extracting time-of-day information
• Examining distributions of crime time
• Identifying correlations between demographic and temporal features
image
Feature Engineering-
A major part of the project was creating meaningful features to boost model performance.
I engineered the following features:
• day_of_week – Monday–Sunday
• is_weekend – binary feature
• time_of_day – Morning, Afternoon, Evening, Night
• season – Winter, Spring, Summer, Fall
• cluster_id – derived using K-Means + PCA
These features helped uncover temporal and behavioral crime patterns.
image
Clustering (Unsupervised Learning)-
I applied K-Means (k=4) to group crime events by hidden behavioral patterns.
The clustering was visualized using PCA (2 components).
The clusters reflected consistent structure in the data, dividing crime events into distinct behavioral groups.
image
Regression Models – Baseline & Improved
I trained multiple regression models to predict crime_time_minutes.
Models included:
• Linear Regression (baseline)
• Linear Regression with engineered features
• Random Forest Regressor
• Gradient Boosting Regressor
Feature engineering led to improvements in MAE, RMSE, and R².
The best regression model was Random Forest Regressor.
image
Feature Importance (Regression)-
The most influential predictor was:
hour – by far the strongest determinant of crime timing.
Other useful features:
• time_of_day groups
• crime_code
• victim_age
• season
image
Classification Task-
I reframed the regression target into three classes using quantile binning:
• Class 0 – early crimes
• Class 1 – mid-day crimes
• Class 2 – late-day crimes
The classes were highly balanced.
For the classification task, I evaluated what is more important:
• Recall is more important than precision, because misclassifying late-night vs. early-day crimes affects planning and public safety.
• False Negatives are more costly than False Positives, since missing a high-risk class is more harmful than overestimating risk.
Classification Models-
I trained three models:
Logistic Regression (multiclass)
Random Forest Classifier (light)
Gradient Boosting Classifier (light)
All three models achieved ~99% accuracy due to clean structure and balance of the target classes.
image
Evaluation & Confusion Matrices-
All models performed nearly identically.
Confusion matrices showed very few misclassifications, mainly between adjacent classes (Class 1 → Class 0 or Class 2).
image
The best-performing model:
Logistic Regression (Multiclass)
Simple, stable, fast, and highly accurate.
Final Winning Model-
The final chosen model was:
Logistic Regression (Multiclass)
It was exported as a .pkl file and uploaded to this HuggingFace repository.
Reflections & Lessons Learned-
Through this assignment I learned:
• How feature engineering dramatically impacts model performance
• How clustering can reveal hidden structure in high-dimensional crime data
• The importance of evaluating classification metrics beyond accuracy
• How to deploy a trained model using HuggingFace
This project built a comprehensive end-to-end ML workflow.