Skip to content

05Menna/Crime-Analysis-Prediction-using-Machine-Learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

🚔 Crime Analysis & Prediction using Machine Learning

A Data Science project focused on analyzing crime incident data, discovering hidden crime patterns, and building machine learning models for crime prediction and clustering.

The project combines data preprocessing, exploratory data analysis (EDA), interactive visualizations, supervised learning, and unsupervised learning to better understand crime distribution across police districts and time.


📌 Project Overview

Crime analysis plays an important role in improving public safety and supporting law enforcement agencies in making data-driven decisions.

This project analyzes historical crime records to answer questions such as:

  • Which crime categories occur most frequently?
  • How are crimes distributed across police districts?
  • Are there seasonal or temporal crime patterns?
  • Can machine learning predict the police district of a crime?
  • Can similar crime incidents be grouped automatically?

🎯 Objectives

  • Clean and preprocess crime datasets.
  • Perform exploratory data analysis (EDA).
  • Discover temporal and geographical crime patterns.
  • Build predictive machine learning models.
  • Apply clustering to identify similar crime profiles.
  • Evaluate model performance using multiple metrics.

📂 Dataset

The project uses historical crime incident records containing both numerical and categorical attributes.

Features include:

  • Crime Category
  • Police District
  • Date & Time
  • Day of Week
  • Resolution
  • Address
  • Longitude
  • Latitude

Target Variable

Police District (PdDistrict)


🔬 Project Workflow

1️⃣ Data Preprocessing

Performed comprehensive preprocessing including:

  • Combined training and testing datasets
  • Removed duplicate records
  • Renamed geographical columns
  • Converted dates into datetime format
  • Extracted temporal features:
    • Year
    • Month
    • Day
    • Hour
  • Checked missing values
  • Prepared categorical features for machine learning

2️⃣ Exploratory Data Analysis (EDA)

Performed extensive EDA to better understand crime trends.

Analysis included:

  • Crime category distribution
  • Crime frequency by police district
  • Crime trends over time
  • Crime resolution analysis
  • Geographic crime distribution
  • Outlier detection
  • Feature statistics

3️⃣ Data Visualization

Created multiple visualizations including:

  • 📊 Bar Charts
  • 📈 Line Charts
  • 🥧 Pie Charts
  • ☁️ Word Cloud
  • 📍 Geographic Scatter Maps
  • 📦 Boxplots
  • 📚 Stacked Bar Charts

These visualizations helped identify crime hotspots, temporal trends, and district-level crime behavior.


4️⃣ Machine Learning

Logistic Regression

Built a multi-class Logistic Regression model to predict the Police Department District.

Preprocessing included:

  • Label Encoding
  • MinMax Scaling

Evaluation Metrics

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • Confusion Matrix
  • Classification Report

5️⃣ Clustering

Implemented K-Medoids Clustering to discover hidden crime patterns.

The clustering workflow included:

  • Gower Distance for mixed numerical and categorical features
  • Optimal cluster selection using Silhouette Score
  • Cluster quality evaluation using:
    • Silhouette Score
    • Calinski-Harabasz Index
    • Davies-Bouldin Index

Representative crime profiles were identified through cluster medoids.


🛠️ Technologies Used

Programming

  • Python

Data Analysis

  • Pandas
  • NumPy

Visualization

  • Matplotlib
  • Seaborn
  • Plotly
  • WordCloud

Machine Learning

  • Scikit-Learn
  • Scikit-Learn-Extra

Algorithms

  • Logistic Regression
  • K-Medoids Clustering

Preprocessing

  • Label Encoding
  • MinMaxScaler

Distance Metric

  • Gower Distance

💡 Skills Demonstrated

  • Data Cleaning
  • Exploratory Data Analysis
  • Feature Engineering
  • Machine Learning
  • Multi-Class Classification
  • Clustering
  • Geospatial Data Analysis
  • Statistical Analysis
  • Data Visualization
  • Model Evaluation

📈 Results

✅ Successfully analyzed crime incidents across multiple police districts.

✅ Identified temporal and geographical crime patterns.

✅ Built a multi-class Logistic Regression classifier.

✅ Applied K-Medoids clustering to identify similar crime profiles.

✅ Evaluated clustering quality using multiple validation metrics.


🚀 Future Improvements

  • Compare additional classification models (Random Forest, XGBoost, LightGBM).
  • Build an interactive crime dashboard using Streamlit.
  • Integrate real-time crime datasets.
  • Apply deep learning techniques for crime prediction.
  • Develop crime hotspot forecasting using time-series models.

About

A Data Science project focused on analyzing crime incident data

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages