Downloads · 30 days
0
tamarabanaim/Crime_in_LA
Crime_in_LA is a machine learning model from tamarabanaim. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Downloads · 30 days
0
Access
Public
Updated Dec 9, 2025
Repo size
185 MB
Likes
0
Public
Click a slice to open those files.
.pkl12.8 MB · 77%
From the Hugging Face model README
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.
Crime_Data_2010_2017 (Kaggle)
https://www.kaggle.com/datasets/cityofLA/crime-in-los-angeles
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.
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.
“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.
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.
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)
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

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.

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.

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.

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

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.
I trained three models:
All three models achieved ~99% accuracy due to clean structure and balance of the target classes.

All models performed nearly identically. Confusion matrices showed very few misclassifications, mainly between adjacent classes (Class 1 → Class 0 or Class 2).

The best-performing model: Logistic Regression (Multiclass) Simple, stable, fast, and highly accurate.
The final chosen model was:
Logistic Regression (Multiclass)
It was exported as a .pkl file and uploaded to this HuggingFace repository.
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.