Skip to content

Instantly share code, notes, and snippets.

@myui
Last active December 20, 2015 15:29
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 myui/6154609 to your computer and use it in GitHub Desktop.
Save myui/6154609 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import sys
from sklearn.externals import joblib
from scipy import sparse as sp
MAX_FEATURES=16777216
def predict(sgd, line):
features = sp.lil_matrix((1,MAX_FEATURES),)
for f in line.split(','):
features[0,int(f)] = 1.0
predicted = sgd.predict_proba(features)
print predicted[0][1]
def main():
if len(sys.argv) != 3:
print >> sys.stderr, \
"Usage: ./sgd-predict <modelfile> <testfile>"
exit(-1)
sgd = joblib.load(sys.argv[1])
f = open(sys.argv[2])
line = f.readline()
while(line):
predict(sgd, line)
line = f.readline()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment