Skip to content

Instantly share code, notes, and snippets.

@cartazio
Created March 15, 2012 02:34
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/2041353 to your computer and use it in GitHub Desktop.
Save cartazio/2041353 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) #
predchunks= read_csv( preddat ,header=None, names=["prediction"] )
print labchunks
print predchunks
preds = predchunks
labels = labchunks
# for labels,preds in izip(labchunks,preddat):
print labels
print preds
# 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