Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ericmaddox/crime-analyst-ai
AI-powered Python project that analyzes crime data, predicts trends using advanced models, and visualizes insights on interactive maps with validation for accuracy and reliability.
https://github.com/ericmaddox/crime-analyst-ai
ai artifical-intelligence crime-analysis crime-data crime-data-analysis crime-prediction crime-statistics ollama ollama-api python python3 scikit-learn
Last synced: 26 days ago
JSON representation
AI-powered Python project that analyzes crime data, predicts trends using advanced models, and visualizes insights on interactive maps with validation for accuracy and reliability.
- Host: GitHub
- URL: https://github.com/ericmaddox/crime-analyst-ai
- Owner: ericmaddox
- License: mit
- Created: 2024-12-17T03:48:17.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-12-20T19:32:52.000Z (about 1 month ago)
- Last Synced: 2024-12-20T20:27:48.926Z (about 1 month ago)
- Topics: ai, artifical-intelligence, crime-analysis, crime-data, crime-data-analysis, crime-prediction, crime-statistics, ollama, ollama-api, python, python3, scikit-learn
- Language: Python
- Homepage:
- Size: 769 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crime Analyst AI
[![Powered by Ollama](https://img.shields.io/badge/Powered%20by-Ollama-blue)](https://ollama.com)This project leverages Python, Folium, the Ollama AI model, and scikit-learn to analyze crime data and predict future crime trends. It visualizes actual crime data on a map and provides narrative insights from the AI model. Additionally, the script now validates predictions using both the Ollama model and historical crime data to ensure predictions are realistic and geographically plausible.
![Crime Analyst AI Map](https://github.com/ericmaddox/crime-analyst-ai/blob/main/media/crime_analyst_ai_map.JPG)
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Outputs](#outputs)
- [Customization](#customization)
- [Why Ollama and scikit-learn](#why-ollama-and-scikit-learn)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgments](#acknowledgments)## Installation
### Prerequisites
Ensure you have Python 3.8 or higher installed on your system. Install the necessary libraries using pip:
```bash
pip install -r requirements.txt
```### Setting Up Ollama
1. **Download and Install Ollama**:
Follow the instructions provided on the [Ollama website](https://ollama.ai) to download and set up Ollama on your local machine.2. **Pull the Ollama Model**:
```bash
ollama pull llama3.2
```3. **Verify Model Availability**:
```bash
ollama list
```## Usage
1. **Prepare the CSV or XLSX File**:
- Ensure your crime data file is named `sample_crime_data.csv` or `sample_crime_data.xlsx` and placed in the same directory as your script.
- If your file has a different name, update the `file_path` variable in the script to match your file name.```python
file_path = 'your_crime_data_file.csv' # Replace with your actual file name
```2. **Modify the Script (if necessary)**:
- Open the script file `crime_analyst_ai.py`.
- Locate the function `run_ollama_predictive_model`.
- Modify the model name within the script to match the Ollama model you are using. For example, if you are using a different model, replace `llama3.2` with your model name.**Example Modification**:
```python
def run_ollama_predictive_model(prompt):
"""Run Ollama AI model to generate or process crime data."""
try:
process = subprocess.run(['ollama', 'run', 'YOUR_MODEL_NAME_HERE', prompt], capture_output=True, text=True, check=True)
```3. **Run the Script**:
- Execute the script:
```bash
python3 crime_analyst_ai.py
```## Outputs
- **Map File**: `crime_analyst_ai_map.html` visualizes both actual crime data and predictive insights.
- **Narrative Analysis File**: `predicted_crime_analysis.txt` contains the narrative output from the Ollama model.## Customization
You can customize the script to include additional machine learning models using scikit-learn for further predictive analysis. The script includes additional validation features:
- **Prediction Validation**: Predictions made by the Ollama model are validated against historical crime data to ensure they make sense geographically and temporally.
- **Likelihood Validation**: A validation step ensures the likelihood values generated by Ollama are within a valid range (0-100%).### Performance Optimization
The script processes large CSV files in chunks to handle large data efficiently.
### Enhanced Visualization
The map visualization includes interactive features, such as tooltips and different marker colors for various crime types.
## Why Ollama and scikit-learn
### Ollama
Ollama is used in this project to leverage advanced AI capabilities for natural language processing and predictive analysis. Predictions made by Ollama are validated against historical crime data to ensure geographical and temporal consistency.### scikit-learn
scikit-learn is not only used for predictive analysis but also for benchmarking and validating the performance of Ollama's predictions. A RandomForestClassifier model provides an independent evaluation of the predictions, and accuracy scores from both models are compared for consistency. This approach helps ensure that the predictions are not only reliable but also robust and grounded in historical data patterns.### How It Acts as a Quality Check for Ollama
- **Evaluation Metric**: The accuracy score from scikit-learn is compared to that of Ollama's predictions to assess performance.
- **Complementary Approach**: By using both Ollama and scikit-learn, you benefit from sophisticated AI insights as well as a solid, interpretable benchmark.
- **Validation**: Predictions from Ollama are validated using geographical and temporal consistency checks to ensure they make sense based on historical data.### Summary
- **Validation**: scikit-learn acts as an independent validator to ensure your predictions are accurate.
- **Benchmark**: Provides a performance benchmark to compare with Ollama's predictions.
- **Insights**: Offers insights into feature importance.
- **Confidence**: Increases confidence in the overall system by ensuring predictions are robust and reliable.By using scikit-learn, you ensure that your AI system is not only making predictions but doing so in a reliable and validated manner, enhancing the credibility and robustness of your crime prediction system.
## Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue to discuss improvements, bug fixes, or new features.
## License
This project is licensed under the MIT License.
## Acknowledgments
I would like to extend my thanks to the following resources and individuals:
- **Folium**: For providing an excellent library to visualize geospatial data on interactive maps. [Folium GitHub](https://github.com/python-visualization/folium)
- **Pandas**: For the powerful data analysis and manipulation capabilities. [Pandas Documentation](https://pandas.pydata.org/pandas-docs/stable/)
- **NumPy**: For the numerical computing capabilities. [NumPy Documentation](https://numpy.org/doc/)
- **Openpyxl**: For reading and writing Excel files. [Openpyxl GitHub](https://github.com/jmcnamara/openpyxl)
- **scikit-learn**: For the robust machine learning tools. [scikit-learn Documentation](https://scikit-learn.org/stable/)
- **Ollama**: For the AI model used for crime data analysis and prediction. [Ollama AI](https://ollama.ai)