Skip to content

Instantly share code, notes, and snippets.

@greeness
greeness / standard.py
Last active August 29, 2015 14:02
step 1.
from datetime import datetime
import numpy as np
age_ranges = ['13-24', '25-35', '36-52', '53-64']
device_options = ['Phone', 'Tablet']
platform_options = ['a', 'i']
def weighted_choice(weights):
totals = np.cumsum(weights)
norm = totals[-1]
import json
from datetime import datetime
from copy import deepcopy
from random import random
def append_features_from_user_block(user_block, user_row):
user_row["num_turns"] = len(user_block)
user_row["min_balance"] = min([x["balance"] for x in user_block])
user_row["max_balance"] = max([x["balance"] for x in user_block])
user_row["min_level"] = min([x["level"] for x in user_block])
@greeness
greeness / gist:da164882b4baa7638e97
Created June 10, 2014 19:47
Random project for dimension reduction
http://users.ics.aalto.fi/ella/publications/randproj_kdd.pdf
@greeness
greeness / board.py
Created July 14, 2014 20:46
board init and hexagon printout
import json
from sys import stdout
from random import choice, seed, shuffle
from copy import deepcopy
basic_shapes = [
[(0,0), (1,0), (2,0)],
[(0,0), (0,1), (0,2)],
[(0,0), (-1,1), (-2,2)],
[(0,0), (-1,0), (-2,0)],
@greeness
greeness / gist:a097d116ac9e60372c7f
Created November 19, 2014 04:35
learning scipy numpy
[Python Scientific Lecture Notes]: (http://scipy-lectures.github.io/index.html)
@greeness
greeness / gist:a547c28d441d2e79f793
Last active August 29, 2015 14:13
cw from Justin Ma's impl
% Exploiting feature covariance in high-dimensional online learning
% http://videolectures.net/aistats2010_ma_efcih/
% http://sysnet.ucsd.edu/projects/url/
function [err,mu,sigma,mem] = cw(X,Y,params)
% X is k features by N instances
% Y is 1 label in {-1,1} by N instances
% params is struct containing options
% err: cumulative mistakes after each example
@greeness
greeness / whirr
Created November 10, 2011 17:12
Install whirr cdh3 release
# launch an ec2 instance with lucid (ubuntu 10.04) e.g. ami-ad36fbc4
# ssh to the machine
################################################################
# install java
# https://ccp.cloudera.com/display/CDHDOC/Java+Development+Kit+Installation
# RELEASE=lucid, which you can find by running lsb_release -c.
################################################################
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
@greeness
greeness / dumbo example
Created November 16, 2011 04:36
dumbo running command line using cache file in hdfs
dumbo start demo_dumbo.py -hadoop /usr/lib/hadoop -input shares -output video_demos -outputformat text -files hdfs://ec2-xxx-xx-xx-xx.compute-1.amazonaws.com:8020/user/ubuntu/users/part-m-00000
### piece of code in demo_dumbo.py
for line in file('part-m-00000'):
print line
# ----------------
dumbo start demo_dumbo.py -hadoop /usr/lib/hadoop -input shares -output video_demos -outputformat text -files hdfs://ec2-xxx-xx-xx-xx.compute-1.amazonaws.com:8020/user/ubuntu/users
@greeness
greeness / gist:1384478
Created November 22, 2011 00:28
create egg file from boto.tar.gz
http://mrtopf.de/blog/en/a-small-introduction-to-python-eggs/
sudo apt-get install python-setuptools
python setup.py bdist_egg
@greeness
greeness / gist:1386945
Created November 22, 2011 21:01
create egg file for scipy
sudo apt-get install gfortran libblas-dev liblapack-dev
cd scipy-0.10.0
python setupegg.py bdist_egg
# wait about 5 minutes on my machine