Last active
August 29, 2015 14:06
-
-
Save gapato/b0ff9360b21749b04381 to your computer and use it in GitHub Desktop.
Compare series
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import genfromtxt, average, median, std, percentile | |
from sys import argv, exit | |
if len(argv) < 3: | |
print 'Usage: {0} <series1.txt> <series2.txt> [map lambda]'.format(argv[0]) | |
exit(1) | |
lam = None | |
if len(argv) == 4: | |
lam = eval(argv[3]) | |
data = [genfromtxt(argv[1]), genfromtxt(argv[2])] | |
if callable(lam): | |
data = map(lam, data) | |
fmt = '{0:.4} vs {1:.4} ({2:+.3}%)' | |
def pct(bef, aft): | |
return (aft-bef)/bef*100 | |
def summary(series): | |
[af, ag] = map(average, series) | |
[mf, mg] = map(median, series) | |
[sf, sg] = map(std, series) | |
print 'Average : '+ fmt.format(af, ag, pct(af, ag)) | |
print 'Median : '+ fmt.format(mf, mg, pct(mf, mg)) | |
print 'Std dev : '+ fmt.format(sf, sg, pct(sf, sg)) | |
print 'Percentiles:' | |
for p in [5, 10, 90, 95]: | |
[pf, pg] = map(lambda x:percentile(x, p), series) | |
print (' {3}% : '+ fmt).format(pf, pg, pct(pf, pg), p) | |
summary(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment