java - (SOLVED) WEKA API LibSVM ClassPath not found -


im trying use libsvm weka api.

my system: win7 weka 3.7.12 libsvm 1.0.6 (installed via package manager)

my code:

import java.io.file; import java.util.random;  import javax.swing.joptionpane;  import weka.classifiers.evaluation; import weka.classifiers.functions.libsvm; import weka.core.instances; import weka.core.converters.converterutils.datasource;  public class libsvmclassifier { // method build svm classifier given data file public static double buildmodel(file dataset){      // new instance of libsvm     libsvm clssvm = new libsvm();       try {         instances data = datasource.read(dataset.getabsolutepath());          // sets label feature         data.setclassindex(data.numattributes()-1);          string opts = "-s 0 -k 0 -d 3 -g 0.0 -r 0.0 -n 0.5 -m 40.0 -c 1.0 -e 0.0010 -p 0.1";           // set options algorithm         clssvm.setoptions(weka.core.utils.splitoptions(opts));           evaluation eval = new evaluation(data);          eval.crossvalidatemodel(clssvm, data, 2, new random(1));          return eval.pctincorrect();        } catch (exception e) {         joptionpane.showmessagedialog(null, e);         e.printstacktrace();     }     return 100; } } 

code called here:

double error = libsvmclassifier.buildmodel(traindataset);

my problem: when run code , first use j48 classifier (code @ end) , afterwards libsvm works fine.

if run libsvm first following error:

java.lang.exception: libsvm classes not in classpath! weka.classifiers.functions.libsvm.buildclassifier(libsvm.java:1636) weka.classifiers.evaluation.evaluation.crossvalidatemodel(evaluation.java:764) weka.classifiers.evaluation.crossvalidatemodel(evaluation.java:374) totd.buildmodel.libsvmclassifier.buildmodel(libsvmclassifier.java:34) totd.gui.gui$5.actionperformed(gui.java:215)

if export project runable jar , use on machine without weka installed error occur if run j48 algorithm first. no matter can't use libsvm on machine.

i have read through other questions regarding problem, there no solution me. in order prevent answers not me here things wont work:

  • explanation how add library project: ive used package manager weka install libsvm , added resulting jar file libsvm weka jar file build path
  • explanation how use libsvm weka gui: want use libsvm weka api in programmatic way, works in weka gui dont need that!!!
  • explanation how change classpath system: want export project jar file , run on system dont have access system class path

possible solutions didnt understand think might work if explains in detail:

j48 code:

import java.io.file;  import javax.swing.joptionpane;  import weka.core.instances; import weka.core.converters.converterutils.datasource; import weka.classifiers.trees.j48; import weka.classifiers.evaluation; import java.util.random;  public class j48classifier { // method build j48 classifier given data file public static double buildmodel(file dataset){      // new instance of tree     j48 clsj48 = new j48();       try {         instances data = datasource.read(dataset.getabsolutepath());          // sets label feature         data.setclassindex(data.numattributes()-1);          string[] options = new string[1];          // unpruned tree         options[0] = "-u";           // set options algorithm         clsj48.setoptions(options);           evaluation eval = new evaluation(data);         eval.crossvalidatemodel(clsj48, data, 2, new random(1));          return eval.pctincorrect();        } catch (exception e) {         joptionpane.showmessagedialog(null, e);         e.printstacktrace();     }     return 100; } } 

my build path http://i.stack.imgur.com/xbkkh.png

thank time. id happy if can point out solution.

greetings

okay, steps how magic work:

  1. search hours , fail
  2. ask on forum
  3. try 5 more minutes , succeed

solution: there 2! libsvm.jar files in weka package folder , need both. try use libsvm using weka package manager go to: (home)\wekafiles\packages\libsvm there find first first libsvm.jar

now go to: (home)\wekafiles\packages\libsvm\lib here find libsvm.jar

add both of these jar build path!!!

greetings


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -