This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bigSmallDict = (df['crime_category'].value_counts(normalize=True) > 0.05).to_dict() | |
# Make a dictionary saying if a category is > 5% of total or not | |
def assignOther(t): | |
if bigSmallDict[t]: | |
return t | |
else: | |
return 'other' | |
# Define a mini function that looks in the dictionary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Grab data from https://drive.google.com/open?id=18IVEIp5qn4OnoWerC4f3e9MUwcBnM5U- | |
df = pd.read_excel('all_data_M_2018.xlsx') | |
df = df[df['o_group']=='detailed'] | |
# Drop broad occupation groups | |
df = df[df['area']==99] | |
# Drop occupations for states, keep only those for the entire US |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rescale(p,rho = 0.001): | |
rhoAbs = abs(rho) | |
if abs(rho) > 10.001: | |
print('Error in rho ') | |
sys.exit(1) | |
out = np.zeros_like(p) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sklearn.model_selection | |
import pandas as pd | |
df = pd.DataFrame(data={'A':[1,2,3],'B':[4,5,6],'C':[1,0,1]}) | |
res = sklearn.model_selection.train_test_split(df[['A','B']],df['C']) | |
# Returns 4 things | |
res[0].shape | |
# (2,2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from __future__ import print_function | |
from keras.models import Sequential | |
from keras.layers import Dense, Activation | |
from keras.layers import LSTM | |
from keras.optimizers import RMSprop | |
from keras.utils.data_utils import get_file | |
import numpy as np | |
import random |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shapefile | |
import seaborn as sns | |
sf = shapefile.Reader("voronoi/voronoi.shp") | |
shapes = sf.shapes() | |
def getMid(bbox): | |
''' | |
Helper function to get midpoint of a bounding box |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Script to map points to administrative units defined by shapefiles | |
Requires shapefiles of administrative units from GADM (http://gadm.org/). | |
Alex Rutherford 2016 | |
''' | |
import scipy.spatial | |
import shapefile,pickle,random,re,collections,csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json,re,csv,re,sys | |
from secrets import * | |
import datetime,time | |
import logging | |
def makeFileName(n,log=False): | |
now=datetime.datetime.now() | |
timeStem='%d_%d_%d_%d_%d' % (now.year,now.month,now.day,now.hour,now.minute) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
pandas.date_range("11:00", "21:30", freq="30min") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from secrets import key | |
def getCountry(s): | |
''' | |
Takes address string as input, queries Google geocoding API and returns country as ISO code | |
''' | |
tempUrl='http://maps.googleapis.com/maps/api/geocode/json?address=%s' % (s) | |
res=requests.get(tempUrl) | |
NewerOlder