This application uses machine learning to answer the question "How safe am I at this location in Minneapolis?". Access the application here
By using an algorithm to convert recently reported crimes in Minneapolis to danger scores for each of the 500 sections (created with clustering), a linear regression model calculates the current danger level of the user's location. The application also displays the user's location on a map along with recently reported crimes in that area.
Crime data comes from Open Data Minneapolis where all past police incidents are hosted. Incidents from the previous day are added at 9:30 am central time each day.
Crime severities come from the Minnesota Courts.
- Python (hosted on Python Anywhere)
- Flask
- Scikit-Learn
- Pandas
- Requests
- Pickle
- HTML
- CSS
- Bootstrap
- JavaScript
- D3
- Jquery
- Leaflet/Mapbox
- Ajax
We used the API from OpenDataMinneapolis . Since each year had its own api string, we developed the code to make multiple API hits, once for each year of requested data. We also used queries within the url to request data within the last x number of days, which allowed us to toggle the amount of data coming back from the API. We then used geopy to get a descriptive location of the crime by inputting the crime's coordinates. All of this functionality was built into functions within the crime_api.py file. The functions were then implemented into the flask server in the app.py file.
- Use API to collect current and past year's crime data
- Use these reported crimes' locations to train a clustering model
- Run Aggregation algorithm to develop the danger score of each cluster for each day that will be considered in the predictive model
- Train linear model using the danger level of the previous 14 days
- Predict the danger level of each cluster for the current day
The Flask app is contained in the app.py file. The flask server contains 2 main routes. The home page that is loaded when the user initially visits the website and the load route which receives and returns data to and from the front-end javascript.
We used javascript leafly to map the user's location and locations of crimes in the user's area. To distinguish the user's maker from the crime markers, we made the user's marker green and the crime markers red. The crime markers have pop-ups that contain details related to the crime including date, time, and type of offense.
The gauge and needle are based off of Preethi Ranjit's tutorial on Creating an SVG Gauge Meter Animation. We modified the code from the tutorial to add our own scale, colors, and size. When a danger score is returned from the server, it will be both reflected on the gauge and displayed underneath it.
- Send user coordinates from browser to server
- The server hits the Open Data Minneapolis API, gets recent crimes in the users area, and calculates a danger score
- The server returns the danger score and nearby crimes to the client
- The gauge is updated with the calculated danger score
- The nearby crimes and the user's location get plotted on the map
- Nearby crimes are also displayed in a table
Overall, this project is a great showcase of multiple tools and languages including machine learning, Python, Javascript, CSS, and HTML. Machine learning is used to predict the danger score for the user's location. Python was used to create the server, access the database, and provide the api endpoints. HTML and CSS were used to create the general page structure and styling. Javascript was used to create the visuals on the page.

