snipplrCallback({"id":22106,"title":"svmlightwrapperm","source":"
  1. function<\/span> Y=svmlight(<\/span>training,test,params)<\/span><\/div><\/li>
  2. % (very) simple wrapper for svmlight<\/span><\/div><\/li>
  3. % write matrices in sparse format to data file that can be used by svmlight.<\/span><\/div><\/li>
  4. % Columns are variables, rows are observations. <\/span><\/div><\/li>
  5. % It is assumed that the first column of the matrix is the target. Targets are elements of {-1,1}.<\/span><\/div><\/li>
  6. %<\/span><\/div><\/li>
  7. % These steps are made: <\/span><\/div><\/li>
  8. % 1. output matlab matrix to text file<\/span><\/div><\/li>
  9. % 2. format text file for svm (awk)<\/span><\/div><\/li>
  10. % 3. create classification model (svm_learn)<\/span><\/div><\/li>
  11. % 4. apply classification model (svm_classify)<\/span><\/div><\/li>
  12. %<\/span><\/div><\/li>
  13. % All files are written in the \/tmp\/ directory, if you are on windows you might want to change that to the current directory ("."). Obviously you need awk installed for this function to work. Assumes svm-light perf is installed in the svmlight subdirectory (change path if necessary). <\/span><\/div><\/li>
  14. %<\/span><\/div><\/li>
  15. % Example: <\/span><\/div><\/li>
  16. % Y=svmlight(data(traininds,:),data(testinds,:),'-c 1 -w 3 -l 10 ');<\/span><\/div><\/li>
  17. % (if you set parameters for svmlight don't forget to include the learning options!)<\/span><\/div><\/li>
  18. %<\/span><\/div><\/li>
  19. % (c) Benjamin Auffarth, 2008<\/span><\/div><\/li>
  20. % licensed under CC-by-sa (creative commons attribution share-alike)<\/span><\/div><\/li>
  21. if<\/span> nargin<3<\/span><\/div><\/li>
  22. params='-c 1 -# 1 -w 3 -l 10 '<\/span>;<\/div><\/li>
  23. end<\/span><\/div><\/li>
  24. trainfile=sparse_write(<\/span>training)<\/span>;<\/div><\/li>
  25. [<\/span>s,w]<\/span>=system(<\/span>[<\/span>'.\/svmlight\/svm_perf_learn '<\/span> params trainfile '.svm2 '<\/span> trainfile '.model'<\/span>]<\/span>)<\/span>;<\/div><\/li>
  26. if<\/span> s <\/div><\/li>