Skip to content

Instantly share code, notes, and snippets.

View szeitlin's full-sized avatar

Sam Zeitlin szeitlin

View GitHub Profile
@szeitlin
szeitlin / infection_graphgist.adoc
Last active August 29, 2015 14:16
Infectious Enthusiasm for Graphs

Mapping Infected Users On Khan Academy


Introduction

Using a graph model to represent Users on the site, we can test what happens when we roll out changes so that associated Users will all see the same version of the site. In other words, we can make changes such that one User gets 'infected' with a new version of the site, and some or all of their connected Users will receive that same version.

@szeitlin
szeitlin / about.md
Last active August 29, 2015 14:16 — forked from antichris/about.md

Fork your own Gist

This is a bookmarklet that adds a fully functional Fork button to your own Gist.

If a Fork button is already present in the page, this bookmarklet will set focus to it instead of adding another one.

The change is temporary and the button will disappear as soon as you navigate away from that Gist (clicking the Fork button does this for you as well).


@szeitlin
szeitlin / comprehension_example.py
Created February 18, 2015 17:35
iterate dict list comprehension
dlist = [{'Bilbo':'Ian','Frodo':'Elijah'},
{'Bilbo':'Martin','Thorin':'Richard'}]
k = 'Bilbo'
#this works as expected
for i in dlist:
... if k in i:
... i[k]
... else:
@szeitlin
szeitlin / nb_cleaner.py
Last active August 29, 2015 14:15
nb_cleaner
__author__ = 'szeitlin'
import argparse
import os
import re
import sys
'''
Helper function for converting python files exported from IPython notebooks into actual programs.
@szeitlin
szeitlin / remove_symbols.py
Created December 2, 2014 00:45
remove symbols from strings (helper function for data cleaning)
def remove_symbols(name):
""" Remove symbols from string and return as one word.
Replace '&' with '_and_'
Replace '/' with '_or_'
Remove spaces
Replace '(' with _
Remove ')'
(str) -> (str)
@szeitlin
szeitlin / remove_spaces.py
Created December 2, 2014 00:44
remove spaces from strings (helper function for data cleaning)
def remove_spaces(name):
'''Helper function removes spaces from string and returns it as a single word.
(str) -> (str)
>>> remove_spaces('Poly CO2')
PolyCO2
'''
nname = name.replace(" ", "")
@szeitlin
szeitlin / drop_max_value.py
Created October 8, 2014 19:21
drop_max_value from a pandas column
def drop_max_value(df, column):
'''
Re-usable function that finds the max value and drops it.
(df, column) -> df
>>> drop_max_value(df, steep)
df
'''
dropthis = df[column].max()
@szeitlin
szeitlin / k-NN.adoc
Last active August 29, 2015 14:06
forkable version

TraitSync k-Nearest Neighbors and Cosine Similarity

Introduction

Using k-nearest neighbors, similarities are calculated between each element in the data set using some distance / similarity metric ^[1]^ that the researcher chooses (there are many distance / similarity metrics), where the distance / similarity between any two elements is calculated based on the two elements' attributes. A data element’s k-NN are the k closest data elements according to this distance / similarity.


1. A distance metric measures distance; the higher the distance the further apart the neighbors. A similarity metric measures similarity; the higher the similarity the closer the neighbors.
@szeitlin
szeitlin / anagram_text.json
Created September 3, 2014 17:54
anagram_text.json
["I may opt for a top yam for amy ."]
["Elvis lives on a dirty dorm room floor over the moor ."]
@szeitlin
szeitlin / delta_range.py
Last active August 29, 2015 14:05
helper script for 'close enough'
__author__ = 'szeitlin'
#helper script to designate allowed range for grouping
def delta_range(delta):
'''
Takes a delta and applies it to generate a reference list for grouping items.
(int) --> list of ints (except zero)