Starting weka from the command line - cannot find the NaiveBayes class

I am trying to start Weka classification from commmand line, but my code is:

java weka.classifiers.bayes.NaiveBayes -t file1.arff -T file2.arff -p

an error message appears:

"Could not find the main class: weka.classifiers.bayes.NaiveBayes. The program will exit."

I run the command in the directory containing weka.jar. Why can't he find the classifier?

+3
source share
2 answers

Try adding an explicit classpath, for example.

java -cp ./weka.jar weka.classifiers.bayes.NaiveBayes -t file1.arff -T file2.arff -p

Some JVMs do not conclude that the jar file you need is in the current directory.

+5
source

WEKA readme

enter image description here

Decision along the way

You can change 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

and then you can run

java weka.classifiers.bayes.NaiveBayes -t $WEKAINSTALL/data/iris.2D.arff -T $WEKAINSTALL/data/iris.2D.arff 
0
source

All Articles