Skip to content

Instantly share code, notes, and snippets.

class OnlineLearner(object):
def __init__(self, **kwargs):
self.last_misses = 0.
self.iratio = 0.
self.it = 1.
self.l = kwargs["l"]
self.max_ratio = -np.inf
self.threshold = 500.
def hinge_loss(self, vector, cls, weight):
@fgregg
fgregg / pstoedit_extract_map.sh
Created August 30, 2012 19:00
Extract shapes for pdf of map
# Requires pstoedit (http://www.pstoedit.net/) and gdal ( http://www.gdal.org/ )
# Convert PDF to DXF format, assign each color to a different layer, and only write the layer that corresponds to
# hex color #B8B9BA
pstoedit -f 'dxf: -ctl -dumplayernames -layers CB8-B9-BA' map_housing_stock_north.pdf parcels.dxf
# Convert DXF to KML
ogr2ogr -f "KML" parcels.kml parcels.dxf
@fgregg
fgregg / near_dupe_functions.py
Created September 21, 2012 13:42
Assignment one, consolidate thes functions
def recordDistances(candidates, data_d, data_model):
# The record array has two elements, the first element is an array
# of floats that has length equal the number of fields. The second
# argument is a array of length 2 which stores the id of the
# considered elements in the pair.
fields = data_model['fields']
field_dtype = [('names', 'a20', len(fields)), ('values', 'f4',
# In local_settings.py
def topic_classifier(title) :
if 'Damage to vehicle claim' in title :
return ['Routine', 'Damage to vehicle claim']
if 'Damage to property claim' in title :
return ['Routine', 'Damage to property claim']
if 'Excessive water rate claim' in title :
# Read in the data
days <- read.csv('all_years.csv')
# Plot all the data
plot(total_count ~ temp_max, days, col=rgb(0,0,0, .3))
# Fit a cubic polynomial to the data
m1 <- lm(total_count ~ temp_max + I(temp_max^2) + I(temp_max^3), days)
# Extract the coefficents
from numpy import *
import pymc
from scipy import stats
from scipy.stats import distributions as d
#parameters about the da
dimensions = 5
observations = 30
shape = (dimensions, observations)
@fgregg
fgregg / fa.py
Last active December 18, 2015 08:09
fa.py
from numpy import *
import pymc
from scipy import stats
from scipy.stats import distributions as d
#parameters about the da
dimensions = 5
observations = 30
shape = (dimensions, observations)
"""
Author: Oliver Mitevski
References:
A Generalized Linear Model for Principal Component Analysis of Binary Data,
Andrew I. Schein; Lawrence K. Saul; Lyle H. Ungar
The code was translated and adapted from Jakob Verbeek's
"Hidden Markov models and mixtures for Binary PCA" implementation in MATLAB
@fgregg
fgregg / graffiti.py
Created June 12, 2013 17:32
Getting images out of Chicago 311 API
import three
chi = three.city('chicago')
yesterday_graffiti = chi.requests(service_code='4fd3b167e750846744000005',
extensions='true',
page_size=500,
start='10-25-2012')
print len(yesterday_graffiti)
City of Chicago
Individual Contributor License Agreement ("Agreement")
Thank you for your interest in [Project Name] by the City of Chicago (the "City"), a municipal corporation and home rule unit of local government existing under the Constitution of the State of Illinois. In order to clarify the intellectual property license granted with Contributions from any person or entity, the City must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of the City and its users; it does not change your rights to use your own Contributions for any other purpose.
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the City. In return, the City shall not use Your Contributions in a way that it believes is contrary to the public benefit. Except for the license granted herein to the City an