Last active
December 20, 2015 15:29
-
-
Save myui/6154609 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#! /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