我已经下载并解压缩了以下WEKA版本weka-3-4-19。这是在Linux操作系统上。我希望通过命令行使用WEKA,但是在执行
时java weka.classifiers.tress.j48.J48
我收到以下错误消息:
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.
有人可以帮我解决这个问题吗?谢谢。
EDIT1:
尝试java -jar weka.jar命令
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.
编辑2:
尝试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.
编辑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.
答案 0 :(得分:10)
这只是意味着weka.classifiers.tress.j48.J48
类不在classpath中。您可以使用java
开关编写-classpath
命令或设置CLASSPATH(永久)变量。另一种方法是使用@jberg指向的-jar
开关。
修改强>
当我查看(我从that site下载了Weka 3-4-19)时,weka.classifiers.tress.j48.J48
包中肯定没有weka.jar
类。可能你正在寻找:
java weka.classifiers.trees.J48
例如:
$ 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.
...
答案 1 :(得分:8)
这个“weka.classifiers.trees.j48.J48”是Weka文档中的拼写错误。它应该是这样的:“weka.classifiers.trees.J48”
而不是设置$ CLASSPATH,替代方案只是放置:
java -cp /pathto/weka.jar weka.classifiers.trees.J48
此外,您可能希望为其提供更多内存,以加快速度:
java -Xmx1G -cp /pathto/weka.jar weka.classifiers.trees.J48
对于运行分类器(就像你试图做的那样),你至少需要给它一些数据,这些数据必须已经转换为ARFF格式。
要对某些数据运行测试,请输入:
java -Xmx1G -cp /path/to/weka.jar weka.classifiers.trees.J48 -t /path/to/whatever.arff
-t用于培训文件。
见这里: Weka Primer
答案 2 :(得分:1)
我没有在linux上使用WEKA,但我认为它只是打包成jar文件,所以你想要:
java -jar weka.jar
您也可以使用weka源jar在自己的代码中使用分类器,方法是将其包含在构建路径中,就像其他jar一样。
答案 3 :(得分:0)
我在macOS中运行Linux Developer版本。您可以复制下面的.bash_profile
并根据您的需要进行修改。
在我回答here时,您可以将以下内容添加到~/.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
在此之后并刷新终端,您应该能够运行以下命令
java weka.classifiers.trees.J48 -t $WEKAINSTALL/data/iris.arff