Machine Learning-Powered Crime Predictive Analysis Platform
- About The Project
- ๐ธ Screenshots
- โญ Repository Visitors
- โจ Features
- ๐ ๏ธ Tech Stack
- ๐ Getting Started
- ๐ Project Structure
- ๐ API Documentation
- ๐บ๏ธ Available Nodes
- ๐ Security Notes
- ๐ค Contributing
- ๐ License
- ๐ฅ Team
- โค๏ธ Made with Love
CrimeIQ is an end-to-end crime analytics and prediction platform developed to assist researchers, law enforcement agencies, and public safety analysts in understanding crime trends within Karachi, Pakistan.
Using historical crime records combined with synthetic demographic information of suspects, the platform trains machine learning models to classify and predict the most probable crime category based on situational and demographic inputs.
๐ก Live Demo: CrimeIQ - Analysis & Prediction Portal (Live Website)
We compared three different machine learning models using the complete ML lifecycle (data cleaning, scaling, handling class imbalances, and splitting):
- Random Forest Classifier (Best Performing): Achieved ~97.8% Accuracy and ~95.6% Precision. Excellent for modeling complex boundaries.
- Decision Tree Classifier: Achieved ~95.2% Accuracy. Highly explainable, but slightly more prone to variance.
- Logistic Regression: Achieved ~70.4% Accuracy. Serving as our baseline linear classifier.
Keep track of the number of analysts, developers, and researchers visiting and cloning this repository:
- ๐ค Interactive Prediction Engine: Input parameters like Karachi Area, suspect age, suspect gender, educational levels, and motives to test model predictions in real-time.
- ๐ Rich Analytics Dashboard: View metrics cards, prediction histories, risk scoring indexes, and categorical predictions distribution.
- ๐ฐ Live Karachi Crime News: Interacts with the Currents API proxy to pull the latest headlines and articles concerning regional security.
- ๐ Glassmorphic User Interface: Sleek, modern styling with dark mode gradients, interactive animations (via AOS), and responsive CSS grids.
- ๐ User Access flows: Included interactive Login and Sign Up interfaces for user account simulation.
Our platform is engineered using modern web technologies and a robust Python data stack:
Follow these steps to set up and run CrimeIQ locally on your system.
Ensure you have the following installed:
-
Clone the Repository:
git clone https://github.com/Blue-Rangoon/Karachi-Crime-Analysis-ML-Model.git cd Karachi-Crime-Analysis-ML-Model -
Set Up a Virtual Environment (Optional but recommended):
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install Dependencies:
pip install -r requirements.txt
-
Environment Configuration: Create a
.envfile in the root directory and add your Currents API Key to enable the live news module:CURRENTS_KEY=your_api_key_here
Start the Flask development server:
python app.pyNote
On the first run, app.py detects if the large Random Forest model (crime_model.joblib, ~354MB) is missing. It will automatically download the pre-trained model file from Google Drive using gdown. This might take a couple of minutes depending on your internet connection.
Once loaded, access the application in your browser at:
http://127.0.0.1:5000
Here is the structural overview of the repository:
Karachi-Crime-Analysis-ML-Model/
โโโ dataset/
โ โโโ karachi_crime.csv # Local dataset
โโโ scripts/
โ โโโ index.js # Authentication & UI controls
โ โโโ dashboard.js # Prediction logic & charts visualization
โโโ styles/
โ โโโ index.css # Base styling & landing page design
โ โโโ dashboard.css # Dashboard layouts & card component designs
โโโ app.py # Main Flask web API routing & server
โโโ train_model.py # Comprehensive training notebook conversion
โโโ train_and_save_model.py # Core data preparation & model generation script
โโโ vercel.json # Deployment serverless configuration
โโโ requirements.txt # Required Python libraries list
โโโ LICENSE # MIT License file
โโโ index.html # Login & Landing page structure
โโโ dashboard.html # Main analytics layout structure
- Route:
/api/features - Method:
GET - Description: Returns lists of encoded categorical labels accepted by models. Used to populate select inputs on frontend dynamically.
- Success Response (200 OK):
{ "Karachi Area": ["Gulshan-e-Iqbal", "Saddar", "Clifton", "Korangi", "..."], "Suspect_Gender": ["Male", "Female", "Unknown"], "Crime_Motive": ["Financial Gain", "Personal Enmity", "Drug Addiction", "..."] }
- Route:
/api/predict - Method:
POST - Headers:
Content-Type: application/json - Payload:
{ "Model": "Random Forest", "Month": "January", "Karachi Area": "Saddar", "Crime Count": 1.0, "Suspect_Age": "21-30", "Suspect_Gender": "Male", "Occupation": "Unemployed", "Education_Level": "Undergraduate", "Crime_Motive": "Financial Gain" } - Success Response (200 OK):
{ "prediction": "ROBBERY", "confidence": 98.4, "risk_score": 98, "risk_level": "High", "top_predictions": [ {"category": "ROBBERY", "probability": 0.984}, {"category": "THEFT", "probability": 0.016} ], "model_name": "Random Forest", "accuracy": 0.978, "precision": 0.956 }
- Route:
/api/news - Method:
GET - Description: Contacts Currents API and returns the top 10 articles matching keywords "Karachi crime".
Below is the collection of interactive interfaces and routes accessible within the system:
- ๐
/(index.html): The landing page containing feature breakdowns, pricing metrics, project details, and auth modal triggers (Login / Sign Up). - ๐
/dashboard.html: The main user hub containing live crime analytics charts, predictions entry forms, risk indicators, and real-time news feeds. - โ๏ธ
/api/features: Fetches categories metadata. - ๐ฎ
/api/predict: Sends configuration variables to models to retrieve predictions. - ๐ฐ
/api/news: News proxy endpoint.
- API Keys: Ensure your
CURRENTS_KEYtoken is stored in the.envfile. Never commit.envconfigurations to public repositories. - CORS Handling:
app.pyimplements CORS headers globally using@app.after_requestto permit requests across developer sub-environments. Be sure to narrow this configuration down for strict production environments. - Robust Model Fallbacks: If a categorical input value is sent that was not present during model encoder fitting, the backend safe-handles it by substituting
Unknownor selecting the default fallback category.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the AGPL-3.0 License. See LICENSE for more information.
Sadia Shoaib Lead Developer |
Saad Ali Rizvi Frontend Developer |
Laiba Idrees Backend Engineer |
Syed Anas Hasan Integration & Technical Specialist |
Alishba Batool Research & Documentation |

