This project aims to predict crime occurrences in Chicago using machine learning techniques. By analyzing historical crime data along with various socio-economic and environmental factors, we aim to build a predictive model that can anticipate the likelihood of different types of crimes in different areas of Chicago.
Crime prediction is a critical task for law enforcement agencies and urban planners to allocate resources effectively and prevent criminal activities. Chicago, being one of the largest cities in the United States, faces various challenges related to crime, making it an ideal candidate for such predictive modeling efforts.
The data used in this project consists of historical crime records obtained from the Chicago Police Department.
Research Paper: https://arxiv.org/pdf/2303.16310.pdf
- Data Collection: Gather historical crime data from the Chicago Police Department and relevant socio-economic and environmental datasets.
- Data Preprocessing: Clean the data, handle missing values, and engineer features.
- Feature Selection: Identify significant features that contribute to crime prediction.
- Model Development: Train various machine learning models such as logistic regression, random forest, and neural networks.
- Model Evaluation: Evaluate model performance using metrics like accuracy, precision, recall, and F1-score.
- Model Deployment: Deploy the best-performing model for real-time predictions.
Some of the inputs used for crime prediction include:
- Time of day
- Day of week
Several machine learning algorithms are explored, including:
- Support Vector Machine
- Random Forest Regression
Hyperparameter tuning and cross-validation techniques are employed to optimize model performance.
The performance of each model is evaluated using metrics such as:
- Accuracy
- Precision
- Recall
- F1-score
Step 1: Download Dataset
- Visit the Chicago Data Portal2
- Download the dataset named "Crimes - 2001 to Present".
- Save the dataset in a folder named data within your project directory.
Dataset Link: https://data.cityofchicago.org/Public-Safety/Crimes-2001-to-Present/ijzp-q8t2/data
Step 2: Obtain Bing Maps API Key
- Go to the Bing Maps Dev Center website (https://www.microsoft.com/en-us/maps/choose-your-bing-maps-api).
- Sign in or create a Microsoft account if needed.
- Generate a new API key for your project.
- Keep the API key secure as it will be used to authenticate requests to the Bing Maps API.
Step 3: Replace API Key in Script
- Clone the repository containing the project code.
- Navigate to the static folder within the project directory.
- Open the script.js file in a text editor.
- Find line 1 where it says const API_KEY = 'YOUR_API_KEY_HERE';.
- Replace 'YOUR_API_KEY_HERE' with your Bing Maps API key.
- Save the changes to script.js.
Step 4: Environment Setup and Installation
Open a terminal or command prompt. Navigate to the project directory.
Create a virtual environment.
- On Windows:
python3 -m venv venv .venv/Scripts/activate
- On macOS/Linux:
python3 -m venv venv source venv/bin/activate
Install the required packages:
pip install -r requirements.txt
Step 5: Model Training
- Navigate to the training folder within the project directory.
- Open the Jupyter Notebook files (*.ipynb) for training the models.
- Follow the instructions within the notebooks to train the models using the downloaded dataset
Step 6: Running the Server
Go back to the root directory of the project. Execute the server.py script:
python server.py
Once the server is running without errors, open a web browser and navigate to (http://Your_IP:5050) to access the application
Test all functionalities to ensure they work correctly
The best-performing model will be deployed as a web application or API, allowing users to input various parameters and receive real-time crime predictions for different locations in Chicago.
This project is licensed under the MIT License.