java - 调用 Weka 时找不到或加载主类

标签 java class classpath weka

我为我的 Java 菜鸟道歉,但我正在尝试从控制台使用 Weka 并且由于某种原因我收到以下错误:

Error: Could not find or load main class weka.classifiers.trees.J48

我正在尝试执行以下命令:

java weka.classifiers.trees.J48 -l C:\xampp\htdocs\frequencyreplyallwords.arff -T C:\xampp\htdocs\testfreqrep.arff -p 0 > C:\xampp\htdocs\output.txt 

我怀疑类路径存在一些问题,但由于我不太了解 Java,是否有任何简单的方法来检查一切是否正确?

谢谢你的帮助

最佳答案

Linux/macOS解决方案

  1. 下载相关版本,例如 Developer Linux 版本 here , 3.9.1 版本,从这个目录here

  2. 将以下行添加到您的 ~/.bash_profile

cat ~/.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

输出

J48 pruned tree
------------------

petalwidth <= 0.6: Iris-setosa (50.0)
petalwidth > 0.6
|   petalwidth <= 1.7
|   |   petallength <= 4.9: Iris-versicolor (48.0/1.0)
|   |   petallength > 4.9
|   |   |   petalwidth <= 1.5: Iris-virginica (3.0)
|   |   |   petalwidth > 1.5: Iris-versicolor (3.0/1.0)
|   petalwidth > 1.7: Iris-virginica (46.0/1.0)

Number of Leaves  :     5

Size of the tree :  9


Time taken to build model: 0.44 seconds
Time taken to test model on training data: 0.01 seconds

=== Error on training data ===

Correctly Classified Instances         147               98      %
Incorrectly Classified Instances         3                2      %
Kappa statistic                          0.97  
Mean absolute error                      0.0233
Root mean squared error                  0.108 
Relative absolute error                  5.2482 %
Root relative squared error             22.9089 %
Total Number of Instances              150     


=== Detailed Accuracy By Class ===

                 TP Rate  FP Rate  Precision  Recall   F-Measure  MCC      ROC Area  PRC Area  Class
                 1.000    0.000    1.000      1.000    1.000      1.000    1.000     1.000     Iris-setosa
                 0.980    0.020    0.961      0.980    0.970      0.955    0.990     0.969     Iris-versicolor
                 0.960    0.010    0.980      0.960    0.970      0.955    0.990     0.970     Iris-virginica
Weighted Avg.    0.980    0.010    0.980      0.980    0.980      0.970    0.993     0.980     


=== Confusion Matrix ===

  a  b  c   <-- classified as
 50  0  0 |  a = Iris-setosa
  0 49  1 |  b = Iris-versicolor
  0  2 48 |  c = Iris-virginica



=== Stratified cross-validation ===

Correctly Classified Instances         144               96      %
Incorrectly Classified Instances         6                4      %
Kappa statistic                          0.94  
Mean absolute error                      0.035 
Root mean squared error                  0.1586
Relative absolute error                  7.8705 %
Root relative squared error             33.6353 %
Total Number of Instances              150     


=== Detailed Accuracy By Class ===

                 TP Rate  FP Rate  Precision  Recall   F-Measure  MCC      ROC Area  PRC Area  Class
                 0.980    0.000    1.000      0.980    0.990      0.985    0.990     0.987     Iris-setosa
                 0.940    0.030    0.940      0.940    0.940      0.910    0.952     0.880     Iris-versicolor
                 0.960    0.030    0.941      0.960    0.950      0.925    0.961     0.905     Iris-virginica
Weighted Avg.    0.960    0.020    0.960      0.960    0.960      0.940    0.968     0.924     


=== Confusion Matrix ===

  a  b  c   <-- classified as
 49  1  0 |  a = Iris-setosa
  0 47  3 |  b = Iris-versicolor
  0  2 48 |  c = Iris-virginica

关于java - 调用 Weka 时找不到或加载主类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15813795/

相关文章:

java - 如何在 Java 中将存储为字符串的日期解析为不同的格式?

java - 从 Java 中的嵌套空对象创建示例 JSON

java - 在Android中解码二进制Android xml资源

类似于 Python 的 Java 类列表

java - 是否可以在 javac(JDK 9)中混合 --class-path 和 --module-path ?

java - Jquery在循环中设置索引位置html标签的值

c++ - 比较同一类的 2 个对象(覆盖 == 运算符)c++

c++ - 我可以将类的数组传递给类数组中的/或者是类数组的子组件吗?

java - Java 的类路径

Hadoop WordCount.java 依赖问题