Skip to content

Instantly share code, notes, and snippets.

View CamDavidsonPilon's full-sized avatar
:shipit:
Learning bio brb

Cameron Davidson-Pilon CamDavidsonPilon

:shipit:
Learning bio brb
View GitHub Profile
import matplotlib
import json
# 538.json is from https://gist.github.com/CamDavidsonPilon/5238b6499b14604367ac
s = json.load( open("538.json") )
matplotlib.rcParams.update(s)
# plots now use FiveThirtyEight styles
@CamDavidsonPilon
CamDavidsonPilon / 538.json
Last active November 28, 2021 07:37
Use the two files below to mimic graphs on 538. www.dataorigami.net/blogs/fivethirtyeight-mpl
{
"lines.linewidth": 2.0,
"examples.download": true,
"patch.linewidth": 0.5,
"legend.fancybox": true,
"axes.color_cycle": [
"#30a2da",
"#fc4f30",
"#e5ae38",
"#6d904f",
@CamDavidsonPilon
CamDavidsonPilon / exponential_survival_data.py
Last active August 29, 2015 13:56
Generate exponential survival data with probability alpha of censorship
def exponential_survival_data(n, cr=0.05, scale=1.):
t = stats.expon.rvs(scale=scale, size=n)
if cr == 0.0:
return t, np.ones(n, dtype=bool)
def pF(h):
v = 1.0*h/scale
return v / (np.exp(v)-1) - cr
@CamDavidsonPilon
CamDavidsonPilon / matplotlib_ipython.py
Created January 27, 2014 15:14
Ideal %matplotlib use
# using %matploblib <backend> also imports the following helpers
from matplotlib import pylplot as plt
from IPython.core.pylabtools import figsize
@CamDavidsonPilon
CamDavidsonPilon / findN.ipynb
Last active January 1, 2016 11:39
find a bound on the expected number of samples needed for an A/B test.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@CamDavidsonPilon
CamDavidsonPilon / biased_coin.py
Created November 24, 2013 22:21
biased coins to unbiased (heh cheating)
import random
p1 = 0.9
p2 = 0.1
N = 10000
s = 0.0
i = 0
while i < N:
@CamDavidsonPilon
CamDavidsonPilon / cover.py
Last active December 19, 2015 03:19
Make cover go now
%pylab
import scipy.stats as stats
print "Best to use custom matplotlibrc located in /styles directory of BMH project."
figure( figsize= ( 8, 11 ) )
#means = np.random.uniform( -4, 4, size = 5 )
means = np.array([ 3.90933614, -1.15148996, 1.70045292, -3.27613385, -0.71058847])
@CamDavidsonPilon
CamDavidsonPilon / pushData.py
Last active December 18, 2015 11:39
reflexive art project.
import android
from time import sleep
from requests import post
droid = android.Android()
SERVER = "http://artech.herokuapp.com"
ID = 0
"""
@CamDavidsonPilon
CamDavidsonPilon / lr.py
Last active December 16, 2015 16:39
linear regression counter example
import numpy as np
from sklearn.linear_model import LinearRegression
#create some random data.
x1 = np.random.randn(250,1)
x2 = 0.001*np.random.randn(250,1) - x1
x3 = np.random.randn(250,1)
# Y is a linear combination of the created data, with
# weights (10,10,0.01)
@CamDavidsonPilon
CamDavidsonPilon / snapple.py
Last active December 16, 2015 12:58
using data from https://gist.github.com/shanselman/5422230 as `filename`, will create a random comment.
import re
import random
CURLY_RE = re.compile( "\{(.*?)\}" )
def spam( filename ):
file = open(filename, "r")