Skip to content

About

An AI-driven Interactive ML dashboard that maps, analyzes, and predicts crime trends in Karachi to help understand where and when incidents occur.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

30 Commits

Folders and files

Repository files navigation

Crime IQ - Karachi Crime Analysis ML Model

Machine Learning-Powered Crime Predictive Analysis Platform

HTML5 CSS3 JavaScript Python Flask Vercel

Last Commit Stars Collaborators Contributors GitHub Issues License Status


Project Preview


๐Ÿ“‹ Table of Contents


About The Project

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)

๐Ÿง  Model Performance & Selection

We compared three different machine learning models using the complete ML lifecycle (data cleaning, scaling, handling class imbalances, and splitting):

  1. Random Forest Classifier (Best Performing): Achieved ~97.8% Accuracy and ~95.6% Precision. Excellent for modeling complex boundaries.
  2. Decision Tree Classifier: Achieved ~95.2% Accuracy. Highly explainable, but slightly more prone to variance.
  3. Logistic Regression: Achieved ~70.4% Accuracy. Serving as our baseline linear classifier.

๐Ÿ“ธ Screenshots

Website Snapshots

Website Page 1


โญ Repository Visitors

Keep track of the number of analysts, developers, and researchers visiting and cloning this repository:

Views Repo Clones

Thank you for visiting! If you find this project useful, please consider giving it a โญ


โœจ Features

  • ๐Ÿค– 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.

๐Ÿ› ๏ธ Tech Stack

Our platform is engineered using modern web technologies and a robust Python data stack:

Frontend

HTML5 CSS3 JavaScript

Backend

Python Flask Flask-CORS

Libraries & Frameworks

Bootstrap 5 Leaflet Bootstrap Icons Scikit-Learn TensorFlow PyCharm

Machine Learning Models & Algorithms

Logistic Regression Random Forest Decision Tree


๐Ÿš€ Getting Started

Follow these steps to set up and run CrimeIQ locally on your system.

Prerequisites

Ensure you have the following installed:

Installation

  1. Clone the Repository:

    git clone https://github.com/Blue-Rangoon/Karachi-Crime-Analysis-ML-Model.git
    cd Karachi-Crime-Analysis-ML-Model
  2. Set Up a Virtual Environment (Optional but recommended):

    python -m venv venv
    # On Windows:
    venv\Scripts\activate
    # On macOS/Linux:
    source venv/bin/activate
  3. Install Dependencies:

    pip install -r requirements.txt
  4. Environment Configuration: Create a .env file in the root directory and add your Currents API Key to enable the live news module:

    CURRENTS_KEY=your_api_key_here

Running the Application

Start the Flask development server:

python app.py

Note

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


๐Ÿ“ Project Structure

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

๐Ÿ“– API Documentation

1. Get Categorical Feature Encodings

  • 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", "..."]
    }

2. Predict Crime Category

  • 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
    }

3. Retrieve Crime News

  • Route: /api/news
  • Method: GET
  • Description: Contacts Currents API and returns the top 10 articles matching keywords "Karachi crime".

๐Ÿ—บ๏ธ Available Nodes

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.

๐Ÿ” Security Notes

  • API Keys: Ensure your CURRENTS_KEY token is stored in the .env file. Never commit .env configurations to public repositories.
  • CORS Handling: app.py implements CORS headers globally using @app.after_request to 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 Unknown or selecting the default fallback category.

๐Ÿค Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

Distributed under the AGPL-3.0 License. See LICENSE for more information.


๐Ÿ‘ฅ Team

Sadia Shoaib Avatar

Sadia Shoaib

Lead Developer

GitHub Profile LinkedIn Profile
Saad Ali Rizvi Avatar

Saad Ali Rizvi

Frontend Developer

GitHub Profile LinkedIn Profile
Laiba Idrees Avatar

Laiba Idrees

Backend Engineer

GitHub Profile LinkedIn Profile

Syed Anas Hasan Avatar

Syed Anas Hasan

Integration & Technical Specialist

GitHub Profile LinkedIn Profile
Alishba Batool Avatar

Alishba Batool

Research & Documentation

GitHub Profile LinkedIn Profile

โค๏ธ Made with Love

Built with passion by Student Development Team

Python Flask Love

ยฉ 2026 CrimeIQ - Karachi Crime Analysis & Prediction Portal. All rights reserved.

About

An AI-driven Interactive ML dashboard that maps, analyzes, and predicts crime trends in Karachi to help understand where and when incidents occur.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages