<jupyter_start><jupyter_text>Crime in San Francisco Spikes After Work Hours For this assignment, I chose to analyze the San Francisco crime data set. I focused on overall crime patterns across time of day and days of the week. I found that crime peaked after work hours, particularly on Thursdays and Fridays.  PreliminariesI decided to use R in the Jupyter environment for this assignment. First, I loaded the libraries I am going to use, along with the dataset. I looked at the summary of the data to get a sense of what I was working with.<jupyter_code>library(ggplot2)
library(lubridate)
library(RColorBrewer)
dfSF = read.csv('F:/GitHub Repos/datasci_course_materials/assignment6/sanfrancisco_incidents_summer_2014.csv',head=TRUE,sep=",")
summary(dfSF)<jupyter_output><empty_output><jupyter_text>Preparing the DataWe can see from the data above that there is a "DayOfWeek" column, which we will use to analyze the data by the day of the week. However, "Time" has crimes down to the minute, and this was too fine of a scale for my tastes to get a sense of the data. Therefore I created a new column for the hour the crime was committed:<jupyter_code>dfSF$Hour<-hour(as.POSIXlt(dfSF$Time, format="%H:%M"))<jupyter_output><empty_output><jupyter_text>Now that the data is in the format I desire, I can start visually looking at the trends. First, I will look at the data by time of day, broken down by the hour column created above.  Analyzing Crime by HourI used ggplot to get a graph of crimes broken down by hour:<jupyter_code>ggplot(dfSF, aes(Hour)) + geom_bar(fill="#1b4f72") + 
labs(title="Histogram for All Crimes")<jupyter_output><empty_output><jupyter_text>We can see the highest rates of crimes are between 5PM-7PM. The lowest rates of crimes are early in the morning, between 3AM and 7AM. Now, we will look at the crime data broken down by days of the week.  Analyzing Crime by Day of WeekI then used ggplots again to graph the crimes broken down by day:<jupyter_code>ggplot(dfSF, aes(DayOfWeek)) + geom_bar(fill="#1b4f72") + 
labs(title="Histogram for All Crimes") + 
scale_x_discrete(name ="Day Of Week", limits=c("Monday","Tuesday","Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))<jupyter_output><empty_output><jupyter_text>We can see that crime is fairly evenly distributed across the days of the week, but there is a noticeable uptick in crime on Friday and through the weekend. Perhaps criminals like to go after tourists in San Francisco, the most popular tourist city in America.  Breaking down Crimes by Both Day of Week and by HourOur results so far show some insight, but it would be valuable to see how crimes break down by both days of the week and by hour. For this plot, I looked at the 2D intensity plot of the days of the week Vs time of day:<jupyter_code>rf <- colorRampPalette(rev(brewer.pal(11,'Spectral')))
r <- rf(32)
redsf <- colorRampPalette(brewer.pal(9,'Reds'))
reds <- redsf(32)
ggplot(dfSF,aes(x=DayOfWeek,y=Hour))+stat_bin2d(bins=24) + 
labs(title="2D Histogram for All Crimes") + 
scale_fill_gradientn(colours=reds) + 
scale_x_discrete(name ="Day Of Week", limits=c("Monday","Tuesday","Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08504034761018, 'fraction_numerical': 0.00931098696461825, 'mean_word_length': 5.7710084033613445, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '573317', 'license': 'Apache-2.0', 'n_tokens_mistral': 1044, 'n_tokens_neox': 982, 'n_words': 422, 'path': 'San Francisco Crimes during the Day and Week.ipynb', 'repo_name': 'Dfenestrator/SFcrime', 'size': '3222'}