Skip to content

Instantly share code, notes, and snippets.

View leggitta's full-sized avatar

Alan Leggitt leggitta

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import pandas as pd
import time
N = int(1e7)
M = 100
counter = 0
df = pd.DataFrame({'y1': np.zeros(N)})
@leggitta
leggitta / fec_create_campaign_expenditures_db.sql
Created June 11, 2017 19:22
Organizes the data from Data for Democracy's campaign expenditure dataset into a mysql database.
CREATE DATABASE campaign_expenditures;
USE `campaign_expenditures`;
# create the filing table
CREATE TABLE filings (
filing_id INT,
fec_committee_id VARCHAR(255),
committee_name VARCHAR(255),
PRIMARY KEY (filing_id)
);
from bokeh.plotting import figure, show
from bokeh.io import output_file
import numpy as np
import pandas as pd
output_file('n_filings.html')
# read the filing data
filings = pd.read_csv('filings.csv')
@leggitta
leggitta / dct2d.py
Last active February 12, 2017 19:29
Computes the two dimensional discrete cosine transform of an image with a single non-zero point
"""
Computes the two dimensional discrete cosine transform, first over rows, than over columns
"""
import numpy as np
import matplotlib.pyplot as plt
# create input image
N1, N2 = 100, 100
x = np.zeros((N1, N2))
@leggitta
leggitta / dct.py
Last active February 8, 2017 23:33
Demonstration of the discrete cosine transform, a variation of the fast fourier transform, often used in image and audio compression
import numpy as np
import matplotlib.pyplot as plt
N = 100
x = np.zeros(N)
x[50] = 1
# compute the dct
X = np.zeros(N)
for k in range(N):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
from scipy.stats import t, zscore
def grubbs(X, test='two-tailed', alpha=0.05):
'''
Performs Grubbs' test for outliers recursively until the null hypothesis is
true.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.