How to Use Weka Java API?
To use the weka API you need to install weka according to your operating system. After downloading the archive and extracting it you’ll find the weka.jar file. The JAR file contains all the class files required i.e. weka API. Now we can find all the information about the classes and methods in the Weka Java API documentation. We need to add this jar as a classpath to our program.
Also, let us discuss the classpath before landing upon the implementation part. So classpath is something that tells the JDK about the external libraries (user class file). In order to add a classpath the recommended way is to use -cp option of JDK commands. If you are using any framework then the classpath can be added to the respective manifest file.
After coding your model using the weka API you can run the program using the following commands
$ javac -cp weka-3-8-5/weka.jar program.java
$ java -cp .:weka-3-8-5/weka.jar program
The weka-3-8-5/weka.jar is the path to the jar file available in the installation.
This will be the desired output generated as shown below: