Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console output for predictions #2

Closed
sebastien-fauvel opened this issue Oct 15, 2013 · 4 comments
Closed

Console output for predictions #2

sebastien-fauvel opened this issue Oct 15, 2013 · 4 comments

Comments

@sebastien-fauvel
Copy link

It would be interesting, for performance reasons, that applications using svm-predict to classify single documents were able to pass the document to classify as a command line argument (instead of a file name), and that the predicted class be printed directly to the output (instead of writing it to a file). This would spare lots of useless IO operations.

What about adding a new usage:

svm-predict [options] test_document model_file

with a console output, for instance:

$ svm-predict '1:-0.14 2:0.2666667 3:0.1074111' model.svm
-1
@kritzikratzi
Copy link

should be quite easy to create this yourself.
roughly like this:

char * path = "classifier.model"; 
svm_model * model = svm_load_model(path);

svm_node * nodes = new svm_node[3]; // num features + 1 
nodes[0].index = 1; 
nodes[0].value = featureValue1; 
nodes[1].index = 2; 
nodes[1].value = featureValue2; 
nodes[2].index = -1; // mark end

int result = svm_predict(model, nodes); 
delete [] nodes; 
svm_free_and_destroy_model(&model);

// now do something with the result ... 

@sebastien-fauvel
Copy link
Author

Thank you for the input! I'll definitely look into this at some point.

@tavianator
Copy link
Contributor

You could also use /dev/stdin and /dev/stdout as the filenames (probably, haven't checked that it works).

@sebastien-fauvel
Copy link
Author

Oh my bad! It actually works :)

> printf "1 1:10\n2 1:20\n" > model.dat
> svm-train -q -g 1 model.dat model.svm
> echo '0 1:20' | svm-predict -q /dev/stdin model.svm /dev/stdout
2

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants