NYC Data Science Academy| Blog
Bootcamps
Lifetime Job Support Available Financing Available
Bootcamps
Data Science with Machine Learning Flagship ๐Ÿ† Data Analytics Bootcamp Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lesson
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories Testimonials Alumni Directory Alumni Exclusive Study Program
Courses
View Bundled Courses
Financing Available
Bootcamp Prep Popular ๐Ÿ”ฅ Data Science Mastery Data Science Launchpad with Python View AI Courses Generative AI for Everyone New ๐ŸŽ‰ Generative AI for Finance New ๐ŸŽ‰ Generative AI for Marketing New ๐ŸŽ‰
Bundle Up
Learn More and Save More
Combination of data science courses.
View Data Science Courses
Beginner
Introductory Python
Intermediate
Data Science Python: Data Analysis and Visualization Popular ๐Ÿ”ฅ Data Science R: Data Analysis and Visualization
Advanced
Data Science Python: Machine Learning Popular ๐Ÿ”ฅ Data Science R: Machine Learning Designing and Implementing Production MLOps New ๐ŸŽ‰ Natural Language Processing for Production (NLP) New ๐ŸŽ‰
Find Inspiration
Get Course Recommendation Must Try ๐Ÿ’Ž An Ultimate Guide to Become a Data Scientist
For Companies
For Companies
Corporate Offerings Hiring Partners Candidate Portfolio Hire Our Graduates
Students Work
Students Work
All Posts Capstone Data Visualization Machine Learning Python Projects R Projects
Tutorials
About
About
About Us Accreditation Contact Us Join Us FAQ Webinars Subscription An Ultimate Guide to
Become a Data Scientist
    Login
NYC Data Science Acedemy
Bootcamps
Courses
Students Work
About
Bootcamps
Bootcamps
Data Science with Machine Learning Flagship
Data Analytics Bootcamp
Artificial Intelligence Bootcamp New Release ๐ŸŽ‰
Free Lessons
Intro to Data Science New Release ๐ŸŽ‰
Find Inspiration
Find Alumni with Similar Background
Job Outlook
Occupational Outlook
Graduate Outcomes Must See ๐Ÿ”ฅ
Alumni
Success Stories
Testimonials
Alumni Directory
Alumni Exclusive Study Program
Courses
Bundles
financing available
View All Bundles
Bootcamp Prep
Data Science Mastery
Data Science Launchpad with Python NEW!
View AI Courses
Generative AI for Everyone
Generative AI for Finance
Generative AI for Marketing
View Data Science Courses
View All Professional Development Courses
Beginner
Introductory Python
Intermediate
Python: Data Analysis and Visualization
R: Data Analysis and Visualization
Advanced
Python: Machine Learning
R: Machine Learning
Designing and Implementing Production MLOps
Natural Language Processing for Production (NLP)
For Companies
Corporate Offerings
Hiring Partners
Candidate Portfolio
Hire Our Graduates
Students Work
All Posts
Capstone
Data Visualization
Machine Learning
Python Projects
R Projects
About
Accreditation
About Us
Contact Us
Join Us
FAQ
Webinars
Subscription
An Ultimate Guide to Become a Data Scientist
Tutorials
Data Analytics
  • Learn Pandas
  • Learn NumPy
  • Learn SciPy
  • Learn Matplotlib
Machine Learning
  • Boosting
  • Random Forest
  • Linear Regression
  • Decision Tree
  • PCA
Interview by Companies
  • JPMC
  • Google
  • Facebook
Artificial Intelligence
  • Learn Generative AI
  • Learn ChatGPT-3.5
  • Learn ChatGPT-4
  • Learn Google Bard
Coding
  • Learn Python
  • Learn SQL
  • Learn MySQL
  • Learn NoSQL
  • Learn PySpark
  • Learn PyTorch
Interview Questions
  • Python Hard
  • R Easy
  • R Hard
  • SQL Easy
  • SQL Hard
  • Python Easy
Data Science Blog > R Shiny > Criminal in San Francisco: Data Trends in Criminal Activity

Criminal in San Francisco: Data Trends in Criminal Activity

Brenna Botzheim
Posted on Oct 30, 2019
The skills the author demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

Introduction

Data shows crime is a pervasive issue in the United States. In Donald Trump's tenure in office, he has taken an aggressive stance towards crime, ordering Federal Judges to pursue the harshest possible punishments.  The policy aims to be 'tough on crime' so as to decrease crime rates in the US. But since we can't curb crime altogether, we had better be able to prepare for it.

Investigating how criminal activity varies is an excellent start to understanding what causes it and how to respond to it. However, criminal activity is different by region, and it pays to look at crime statistics around you rather than just the country as a whole. I live in the San Francisco Bay area and I wanted to investigate the make up of crime in San Francisco by variables like type of incidents, time, and location.

Crime statistics have a variety of uses in different organizations: The San Francisco city government can use the data to investigate trends in crime by location and time. With this data, the city of SF could make informed decisions about future changes in SFPD routes, schedules, and big picture plans to reduce crime. Companies can use them when deciding where to place a new office or when to schedule deliveries.

Collecting Data

At a micro level, an individual intending to purchase a home can investigate the criminal activity near potential homes and incorporate that into their decision making. Alternatively, a curious current citizen in SF like myself could see what neighborhoods have the highest level of criminal activity or what time of day incurs the most crime.  

However, data alone is hard to glean information from. R Shiny provides clean, easy to use functionality that I harnessed to create an app that is intuitive for users of any background. The goal of the app is to provide dynamic visualizations to help describe the underlying data on criminal activity in SF. It filters the data by time, location, and type of incident and creates dynamic graphical displays of the data to easily observe trends. In the following I will show some examples of what the app can do and key insights that it has provided about SF crime reports.

Data

The data used in this project comes from SF Open Data, a transparency initiative introduced in San Francisco in 2009 to promote innovation by making data that is collected and maintained by the city, publicly available. Data collected by the government is a great source of insights into many topics, including public health, the economy, transportation, and criminal activity. 

The data itself consists of all incident reports filed by the SF police department as well as "by individuals through self-service online reporting for non-emergency cases" dating back to January 1st, 2018 (when SF made changes to it's reporting structure). As such, the incidents include both criminal activity and non-criminal incidents. 

NOTE: Criminal activity and the relative safety of neighborhoods is not simply a geographical issue. There are more complicated processes working behind the scenes that create geospatial distinctions in crime rates. For example, poorer neighborhoods tend to have higher crime, which sounds intuitive: if someone is having trouble putting food on the table for their family, they are more likely to resort to criminal means to do so.

But the issue goes deeper: schools in poorer neighborhoods tend to have less funding, higher drop out rates, and less experienced instructors, creating what has been termed the "school to prison pipeline." The goal of this project was not to investigate these structural processes, but it is important to note that they exist and should be considered in any informed decisions on this topic.

Data Analysis

Location

The below maps show arson incidents and juvenile offenses clustered into groups. The first incident, arson, shows the more common dispersion of incident reports in San Francisco, with the highest concentration in downtown SF (Along market street and in the Tenderloin and Mission districts) and a lower concentration of reports in other areas of the city. Notably, juvenile offenses have almost an opposite dispersion, with an abnormally high concentration in the Taraval district.

  • Criminal in San Francisco: Data Trends in Criminal Activity
  • Criminal in San Francisco: Data Trends in Criminal Activity

A little investigatory google search revealed that the area where those incidents occurred was at the Edgewood Center for Children and Families, a nonprofit organization that provides behavioral health services to the community, with its focus mainly on providing services for children. Knowing that potentially troubled children are brought to this location for help better explains this phenomenon.

Next, we can see below that filtering for drug offenses reveals that the Tenderloin district accounts for far more incidents than the other districts (even though it is geographically the smallest). The Tenderloin is notorious for it's nightlife and seedy characteristics, however I did not expect to find such high reports of drug offenses in this part of the city. In the Park district, there is a well known street intersection (Haight-Ashbury) known for it's hippie culture and promotion of drug use, but the Park district does not even rank among the top three in the below graph.

Criminal in San Francisco: Data Trends in Criminal Activity

It is true that Haight-Ashbury's reputation for hippie culture now predominantly exists historically. The area remains active and bustling, but by now more commonly with tourists visiting shops that profit from the area's reputation. Thus, perhaps it is not so surprising that Haight-Ashbury does not incur as much drug-related criminal activity as other districts.

Time

Below is a graph of all incident reports by day of the week. Overall, we can see that criminal activity is the highest on Fridays and lowest on Sundays. This seems pretty intuitive, given that people tend to go out on Fridays and stay home on Sundays. In general though the differences are rather small by day.

Next, let's take a look at an incident that doesn't follow the overall pattern:

Here we see that robberies are the most common on Sundays. This graph is almost the opposite of what we found the overall trend to be. Robberies are mainly defined as theft of a victim by force. In comparison, burglaries refer to theft while trespassing on a property. The below graph shows the amount of burglaries by day of the week:

The burglary graph is approximately the inverse of the robbery graph. This is a rather striking difference and would be an area for further investigation to determine what causes these differences.

In the next graph we can see that overall, incidents are most likely to occur in the middle of the day or in the evening.

Below, when we filter by liquor law violations we see that much fewer incidents occur during the morning, and much more occur at night. Further investigation within the Shiny app shows that weekends are also much more common for liquor law violations.

This is pretty intuitive given that most people go out drinking in the evenings on weekends. On the other hand, if you sort by civil sidewalk complaints, far more occur during the morning (presumably as people head off to work), and so few occur at night we can't even see it in the graph.

Time Line

Lastly, let's take a look at a time line of incident reports of burglaries. The below image shows the daily frequency of burglary reports over approximately 2 years. Though it varies, there seems to a general trend towards fewer daily burglary reports over time. This is an interesting find that requires a more vigorous analysis to test if a significant downward trend exists.

An alternative explanation could be that police officers have begun using the "burglary" incident category less frequently, instead opting to categorize an incident as "larceny theft". The main difference between these two categories is that burglaries refer to theft from buildings, while larceny theft refers to theft from vehicles. However, a portion of theft from buildings are categorized under larceny theft. (This information can be investigated under the data tab within the app, where it shows sub-categories and incident descriptions.) Below is the same graph for "larceny theft" :

In the above we do see an increase in larceny theft reports around the same time that the decrease in burglary incidents occur.

Comparing Incidents

The shiny app I created also offers a tab for directly comparing incidents. In the below graph we can see the reports of motor vehicle theft compared with reports of recovered vehicles by neighborhood. The first thing that stands out is that vehicles are more commonly recovered outside of San Francisco. Additionally, most neighborhoods report more vehicle thefts than vehicles recovered, with the exception of the Tenderloin district. Here we see relatively few vehicle thefts reported, and more vehicles recovered.

Summary

Investigating how criminal activity varies provides valuable insights for the government, for companies, and for individuals to make informed decisions. Experienced police officers may have a good sense about what parts of the city experience higher crime, but having the data to back up that intuition can make the difference between implementing a useful change or an unneeded change.

Many more interesting observations can be made using the app, which can be found here: https://bbotzheim.shinyapps.io/SF_incident_reports/

It is my goal to further develop this app by adding San Francisco's historical data prior to 2018 when changes were made to the reporting structure. This data dates all the way back to 2003 and could be provide more trends over time. 

Further developing the functionality in the app, such as being able to pick and choose multiple incidents, or filter by day of week and time of day could also provide useful insights.

About Author

Brenna Botzheim

Brenna Botzheim is an associate EOV Analyst at StormGeo. Brenna holds a Bachelors degree from San Francisco State University where she studied sociology and mathematics. In her spare time, Brenna continues to develop her skills in statistical data...
View all posts by Brenna Botzheim >

Leave a Comment

No comments found.

View Posts by Categories

All Posts 2399 posts
AI 7 posts
AI Agent 2 posts
AI-based hotel recommendation 1 posts
AIForGood 1 posts
Alumni 60 posts
Animated Maps 1 posts
APIs 41 posts
Artificial Intelligence 2 posts
Artificial Intelligence 2 posts
AWS 13 posts
Banking 1 posts
Big Data 50 posts
Branch Analysis 1 posts
Capstone 206 posts
Career Education 7 posts
CLIP 1 posts
Community 72 posts
Congestion Zone 1 posts
Content Recommendation 1 posts
Cosine SImilarity 1 posts
Data Analysis 5 posts
Data Engineering 1 posts
Data Engineering 3 posts
Data Science 7 posts
Data Science News and Sharing 73 posts
Data Visualization 324 posts
Events 5 posts
Featured 37 posts
Function calling 1 posts
FutureTech 1 posts
Generative AI 5 posts
Hadoop 13 posts
Image Classification 1 posts
Innovation 2 posts
Kmeans Cluster 1 posts
LLM 6 posts
Machine Learning 364 posts
Marketing 1 posts
Meetup 144 posts
MLOPs 1 posts
Model Deployment 1 posts
Nagamas69 1 posts
NLP 1 posts
OpenAI 5 posts
OpenNYC Data 1 posts
pySpark 1 posts
Python 16 posts
Python 458 posts
Python data analysis 4 posts
Python Shiny 2 posts
R 404 posts
R Data Analysis 1 posts
R Shiny 560 posts
R Visualization 445 posts
RAG 1 posts
RoBERTa 1 posts
semantic rearch 2 posts
Spark 17 posts
SQL 1 posts
Streamlit 2 posts
Student Works 1687 posts
Tableau 12 posts
TensorFlow 3 posts
Traffic 1 posts
User Preference Modeling 1 posts
Vector database 2 posts
Web Scraping 483 posts
wukong138 1 posts

Our Recent Popular Posts

AI 4 AI: ChatGPT Unifies My Blog Posts
by Vinod Chugani
Dec 18, 2022
Meet Your Machine Learning Mentors: Kyle Gallatin
by Vivian Zhang
Nov 4, 2020
NICU Admissions and CCHD: Predicting Based on Data Analysis
by Paul Lee, Aron Berke, Bee Kim, Bettina Meier and Ira Villar
Jan 7, 2020

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day ChatGPT citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay football gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income industry Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI

NYC Data Science Academy

NYC Data Science Academy teaches data science, trains companies and their employees to better profit from data, excels at big data project consulting, and connects trained Data Scientists to our industry.

NYC Data Science Academy is licensed by New York State Education Department.

Get detailed curriculum information about our
amazing bootcamp!

Please enter a valid email address
Sign up completed. Thank you!

Offerings

  • HOME
  • DATA SCIENCE BOOTCAMP
  • ONLINE DATA SCIENCE BOOTCAMP
  • Professional Development Courses
  • CORPORATE OFFERINGS
  • HIRING PARTNERS
  • About

  • About Us
  • Alumni
  • Blog
  • FAQ
  • Contact Us
  • Refund Policy
  • Join Us
  • SOCIAL MEDIA

    ยฉ 2025 NYC Data Science Academy
    All rights reserved. | Site Map
    Privacy Policy | Terms of Service
    Bootcamp Application