Skip to content

Instantly share code, notes, and snippets.

@cartazio
Created March 15, 2012 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cartazio/2041199 to your computer and use it in GitHub Desktop.
Save cartazio/2041199 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
from pandas import *
from numpy import *
import sys
from itertools import *
from math import exp
def logistic(num):
return (exp(num)/(1+exp(num)))
fromvw = sys.argv[1] # blah.vw , the file that has the example vowpal learns from
preddat = sys.argv[2] # blah-run.dat , prediction output file from vw blah-run
target = sys.argv[3] # pairedLabelVs.csv , csv file with prediction and
fl = open(target,"w")
fl.write("isclick, prediction\n")
# i have written this code but I have not tested it
labchunks = read_csv(fromvw, sep=" ",header=None,chunksize = 100000) #
predchunks= read_table( preddat ,header=None, names=["prediction"],chunksize = 100000 )
print labchunks
print predchunks
for labels,preds in izip(labchunks,preddat):
# print labels
# print predd
# currentrange = min( len(labels.ix[:,0]), len(predd.ix[:,0]))
# print preds
for lbl,prd in zip( labels.ix[:,"X.1"] ,preds.prediction):
fl.write(str(lbl) + "," +str(logistic(prd))+ "\n" )
fl.flush()
fl.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment