How abhayrautela213/crime-rate-prediction works
Project Type & Purpose
• This is a full-stack prediction application. Its primary goal is to take input parameters (city, crime type, year) from a web user interface and output a prediction made by the machine learning model.
• The README details the scope (crime prediction on historical data between 2014 and 2021 using a Random Forest model) and explains the usage and user interactions.
File Structure
• Frontend:
• The “templates” directory holds HTML files (index.html and result.html) which are likely used by a web framework (e.g., Flask) to render the user interface.
• The “static” directory has assets such as CSS (styles.css), JavaScript (main.js), and images, which provide UI styling and interactivity.
• Backend:
• The file “app.py” appears to be the primary script that sets up the web server, routes user requests, and orchestrates the overall application logic.
• “crp.ipynb” is a Jupyter Notebook, likely used for model development and testing. It provides insights into the experimental model building process.
• “requirements.txt” lists all dependencies, indicating the technical stack (e.g., scikit-learn, Flask) required by the project.
• Machine Learning Components:
• The “Model” folder contains “model.pkl”, which is the pre-trained Random Forest Regression model used for predictions.
• The “Mappings” directory includes text files mapping cities and types; these are likely used to convert user-friendly names into formats that the model can accept.
• The “Dataset” directory contains Excel files with historical crime data, which may have been used for training or validating the model.
• Reports & Documentation:
• The “Report” directory holds documentation and presentation files detailing the project’s literature survey, design, and performance results.
Key Components
a. Web Frontend:
• Templates (HTML) for input (index.html) and output (result.html)
• Static assets (CSS, JS, images) used for UI styling and interactivity
b. Web Server & Application Logic:
• The main controller “app.py” handles HTTP requests, processes form data, and coordinates with the backend prediction logic.
c. Machine Learning Model:
• The pre-trained “model.pkl” encapsulated in the “Model” directory represents the core predictive engine.
• Mappings (city and crime type) from the “Mappings” folder enable the correct pre-processing of inputs.
d. Data Storage/Source:
• Datasets (both “crp.xlsx” and “new_dataset.xlsx” in the “Dataset” folder) provide underlying historical data for reference or future model improvements.
e. Ancillary Documentation:
• The “Report” folder contains design and presentation docs. Although not directly contributing to runtime architecture, they offer context about design decisions, and insights into evaluation/testing.
Relationships and Interactions
• The frontend (templates and static assets) sends user input (city, crime category, and year) to the back end via the web server implemented in “app.py”.
• “app.py” then utilizes the mappings to pre-process this input. It loads the machine learning model (model.pkl) to perform prediction.
• The predicted crime rate is then passed back to the frontend where it is rendered on “result.html” for the user.
• Underneath, there’s an assumed separation of concerns where the data (master datasets and mappings) and machine-learning model are isolated from the web server code.
Architectural Patterns/Design Principles
• Separation of Concerns: Clearly delineates the UI (templates/static), application logic (app.py), and machine learning components (Model, Mappings, Dataset).
• MVC-Like Approach (loosely applied): The “model” is handled via machine learning (in a separate module), the “view” through the HTML templates, and the “controller” in app.py.
• Dependency Management: Use of requirements.txt signifies proper dependency management.