在 Linux 上运行 WEKA

发布于 2024-11-19 09:03:22 字数 2644 浏览 4 评论 0原文

我已经下载并解压了以下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.

有人可以帮我解决这个问题吗?谢谢。


编辑1:

在尝试 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.

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.classifiers.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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

随波逐流 2024-11-26 09:03:22

这仅仅意味着 weka.classifiers.tress.j48.J48 类不在 类路径。您可以使用 -classpath 开关编写 java 命令或设置 CLASSPATH(永久)变量。另一种方法是使用 @jberg 指出的 -jar 开关。

编辑:

正如我检查的那样(我从 该站点)在 weka.jar 包中肯定没有 weka.classifiers.tress.j48.J48 类。您可能正在寻找:

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.
...

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.
...
以为你会在 2024-11-26 09:03:22

这个“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 入门

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

子栖 2024-11-26 09:03:22

我没有在linux上使用过WEKA,但我认为它只是打包为jar文件,所以你想要:

java -jar weka.jar

你也可以使用weka源jar来使用通过将分类器包含在您自己的代码中,将其包含在您的构建路径中,就像其他 jar 一样。

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.

生活了然无味 2024-11-26 09:03:22

我在 macOS 中运行 Linux Developer 版本。您可以复制下面的.bash_profile并根据您的需要进行修改。

正如我在此处回答的那样,您可以将以下内容添加到您的 ~/.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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文