Skip to content

Instantly share code, notes, and snippets.

View ajschumacher's full-sized avatar

Aaron Schumacher ajschumacher

View GitHub Profile
@ajschumacher
ajschumacher / snippets.md
Created July 18, 2023 18:40
public snippets

chi-squared test

import scipy.stats

obs = np.array([[a, b],
                [c, d]])
_, p, _, _ = scipy.stats.chi2_contingency(obs)
@ajschumacher
ajschumacher / scoring.R
Created August 17, 2014 17:46
code for a blog post on Wilson scoring vs. Laplace smoothing
par(pty='s')
par(mfrow=c(1, 2))
ci_lower_bound <- function(pos, n, confidence) {
if (n == 0) return(0)
z = qnorm(1 - (1 - confidence) / 2)
p = pos / n
(p + z^2 / (2*n) - z * sqrt((p * (1-p) + z^2 / (4*n)) / n )) /
(1 + z^2 / n)
#!/usr/bin/env python
import sys
import csv
def MeanAveragePrecision(valid_filename, attempt_filename, at=10):
at = int(at)
valid = dict()
for line in csv.DictReader(open(valid_filename,'r')):
valid.setdefault(line['source_node'],set()).update(line['destination_nodes'].split(" "))

SQL workshop!


Get everything you can about people.

select * from people

-- comments

@ajschumacher
ajschumacher / README.md
Last active January 5, 2022 23:30 — forked from mbostock/.block
Interactive D3 view of sklearn decision tree
@ajschumacher
ajschumacher / code.py
Last active May 26, 2021 19:36
Python 3.7.4 exception hierarchy
# inspired by and based on:
# https://julien.danjou.info/python-exceptions-guide/
# https://github.com/jd/julien.danjou.info/blob/master/bin/generate-python-exceptions-graph.py
import builtins
edges = set()
synonyms = {}
for name in dir(builtins):
item = getattr(builtins, name)
@ajschumacher
ajschumacher / mspacman.py
Created January 12, 2017 22:27
play Ms. Pacman w/ OpenAI gym
import time
import pygame
import gym
frame_time = 1.0 / 15 # seconds
pygame.init()
import random
import math
def mean(elements):
return sum(elements) / len(elements)
def euclidean_dist(first, second):
assert len(first) == len(second)
return sum((f - s)**2 for f, s in zip(first, second))**0.5
@ajschumacher
ajschumacher / build_logins.sh
Last active March 6, 2018 19:29 — forked from JoshData/build_logins.sh
script for making users for multi-user RStudio
#!/bin/bash
# Start an AWS instance with one of the AMIs provided by:
# http://www.louisaslett.com/RStudio_AMI/
#
# Get this script and make executable.
# wget THE_RAW_URL
# chmod +x build_logins.sh
#
# Then use this script to create many logins on the system.
@ajschumacher
ajschumacher / test.rst
Last active January 19, 2017 07:01
github fails to render rst email links properly