snipplrCallback({"id":22106,"title":"svmlightwrapperm","source":"
function<\/span> Y=svmlight(<\/span>training,test,params)<\/span><\/div><\/li> % (very) simple wrapper for svmlight<\/span><\/div><\/li> % write matrices in sparse format to data file that can be used by svmlight.<\/span><\/div><\/li> % Columns are variables, rows are observations. <\/span><\/div><\/li> % It is assumed that the first column of the matrix is the target. Targets are elements of {-1,1}.<\/span><\/div><\/li> %<\/span><\/div><\/li> % These steps are made: <\/span><\/div><\/li> % 1. output matlab matrix to text file<\/span><\/div><\/li> % 2. format text file for svm (awk)<\/span><\/div><\/li> % 3. create classification model (svm_learn)<\/span><\/div><\/li> % 4. apply classification model (svm_classify)<\/span><\/div><\/li> %<\/span><\/div><\/li> % 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> %<\/span><\/div><\/li> % Example: <\/span><\/div><\/li> % Y=svmlight(data(traininds,:),data(testinds,:),'-c 1 -w 3 -l 10 ');<\/span><\/div><\/li> % (if you set parameters for svmlight don't forget to include the learning options!)<\/span><\/div><\/li> %<\/span><\/div><\/li> % (c) Benjamin Auffarth, 2008<\/span><\/div><\/li> % licensed under CC-by-sa (creative commons attribution share-alike)<\/span><\/div><\/li> if<\/span> nargin<3<\/span><\/div><\/li> params='-c 1 -# 1 -w 3 -l 10 '<\/span>;<\/div><\/li> end<\/span><\/div><\/li> trainfile=sparse_write(<\/span>training)<\/span>;<\/div><\/li> [<\/span>s,w]<\/span>=system(<\/span>[<\/span>'.\/svmlight\/svm_perf_learn '<\/span> params trainfile '.svm2 '<\/span> trainfile '.model'<\/span>]<\/span>)<\/span>;<\/div><\/li> if<\/span> s <\/div><\/li> disp<\/span><\/a>(<\/span>'error in executing smv-light!'<\/span>)<\/span>;w,<\/div><\/li> error<\/span><\/a>(<\/span>'svm_perf_learn not found or returned error'<\/span>)<\/span>;<\/div><\/li> end<\/span><\/div><\/li> testfile=sparse_write(<\/span>test)<\/span>;<\/div><\/li> [<\/span>s,w]<\/span>=system(<\/span>[<\/span>'.\/svmlight\/svm_perf_classify -v 0 '<\/span> testfile '.svm2 '<\/span> trainfile '.model '<\/span> testfile '.dat'<\/span>]<\/span>)<\/span>;<\/div><\/li> if<\/span> s <\/div><\/li> disp<\/span><\/a>(<\/span>'error in executing smv-light!'<\/span>)<\/span>;w,<\/div><\/li> error<\/span><\/a>(<\/span>'svm_perf_classify not found or returned error'<\/span>)<\/span>;<\/div><\/li>