开发者

run WEKA on Linux

I have downloaded and unzipped the following WEKA version weka-3-4-19. This is on a linux operating system. I wish to use WEKA through the command line, however on executing

java weka.class开发者_JAVA技巧ifiers.tress.j48.J48

I get the following error message:

Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/tress/j48/J48
Caused by: java.lang.ClassNotFoundException: weka.classifiers.tress.j48.J48
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: weka.classifiers.tress.j48.J48.  Program will exit.

Can someone help me resolve this? Thank you.


Edit1:

On trying the java -jar weka.jar command

java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
    at java.awt.Window.<init>(Window.java:432)
    at java.awt.Frame.<init>(Frame.java:403)
    at javax.swing.JFrame.<init>(JFrame.java:202)
    at weka.gui.GUIChooser.<init>(GUIChooser.java:98)
    at weka.gui.GUIChooser.main(GUIChooser.java:285)

No X11 DISPLAY variable was set, but this program performed an operation which requires it.

Edit 2:

On trying java.weka.classifiers.trees.J48

Exception in thread "main" java.lang.NoClassDefFoundError: weka/classifiers/tress/J48
Caused by: java.lang.ClassNotFoundException: weka.classifiers.tress.J48
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: weka.classifiers.tress.J48.  Program will exit.

Edit 3:

{cslinux2:~/weka-3-4-19} echo $CLASSPATH
/people/cs/j/jld082000/weka-3-4-19/weka.jar:
{cslinux2:~/weka-3-4-19} java weka.classifiers.trees.J48

Weka exception: No training file and no object input file given.

General options:

-t <name of training file>
    Sets training file.
-T <name of test file>
    Sets test file. If missing, a cross-validation will be performed on the training data.


That simply means weka.classifiers.tress.j48.J48 class is not in classpath. You can write java command with -classpath switch or set CLASSPATH (permanent) variable. Another way is to use -jar switch as pointed by @jberg.

EDIT:

As I checked (I downloaded Weka 3-4-19 from that site) there is definitely no weka.classifiers.tress.j48.J48 class in weka.jar package. Probably you are looking for:

java weka.classifiers.trees.J48

For example:

$ export CLASSPATH=/home/grzegorz/weka-3-4-19/weka.jar:.
$ echo $CLASSPATH 
/home/grzegorz/weka-3-4-19/weka.jar:.
$ java weka.classifiers.trees.J48

Weka exception: No training file and no object input file given.

General options:

-t <name of training file>
    Sets training file.
...


This "weka.classifiers.trees.j48.J48" is a typo in the Weka documentation. It's should be this: "weka.classifiers.trees.J48"

And instead of setting the $CLASSPATH the alternative is just to put:

java -cp /pathto/weka.jar weka.classifiers.trees.J48

Also, you might want to give it more memory to play with, to speed things up:

java -Xmx1G -cp /pathto/weka.jar weka.classifiers.trees.J48

For running a classifier (like you are attempting to do) you need to at least give it some data, which must already be converted to ARFF format.

To run a test on some data enter:

java -Xmx1G -cp /path/to/weka.jar weka.classifiers.trees.J48 -t /path/to/whatever.arff

-t is for training file.

See here: Weka Primer


I haven't used WEKA on linux, but I think it is just packaged as a jar file, so you want to:

java -jar weka.jar

You can also use the weka source jars to use the classifiers in your own code by including it in your build path like you would other jars.


I run the Linux Developer version in macOS. You can copy the .bash_profile below and modify to your needs.

As I answered here, you can just put the following to your ~/.bash_profile

export R_HOME="/Applications/R.app/Contents/MacOS/R"    #for WEKA MLR R plugin 
export CLASSPATH="/Applications/weka-3-9-1/weka.jar"    #for WEKA commandline
export WEKAINSTALL="/Applications/weka-3-9-1"

export WEKA_HOME="/Applications/weka-3-9-1"
export CLASSPATH=$CLASSPATH;$WEKA_HOME/weka.jar
export HEAP_OPTION=-Xms4096m -Xmx8192m
export JAVA_COMMAND java $HEAP_OPTION

after this and refreshing the terminal, you should be able to run the following command

java weka.classifiers.trees.J48 -t $WEKAINSTALL/data/iris.arff
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜