First Google , the Weka software download down, after the installation is complete, in the Weka installation directory has a Weka.jar package.
Once you have added the package to the project, you can call the functions in Weka .
A little bit more aboutweka Basics in weka in the directory, there is a data folder, The data set is stored in the first data set contact-lenses.arff For example, use editplus or another editor opens the dataset, with a% beginning with some comments , @relation represents the name of the dataset, @attribute represents property properties, < Span style= "font-family: ' Times New Roman ';" > @data is the dataset, generally the last column is the category (in LIBSVM The first column in the is a category).
below I have written a trivial weka Entry code:
Package instancetest;
Import Java.io.FileReader;
Import weka.core.Instances;
Public class instancetest
{
Public static Instances getfileinstances (String fileName) throwsException
{
FileReader frdata = new FileReader (fileName);
Instances data = new Instances (frdata);
return data;
}
Public static void main (string[] args) throws Exception
{
Instances Instances = getfileinstances( "F://program Files//weka-3-4//data//contact-lenses.arff");
All the data sets are entered
//system.out.println (instances);
How many samples are available in the data set with Numinstances
for ( int i = 0; i < instances.numinstances (); i++)
{
Instance (i) is to obtain the first sample
System. out . println (Instances.instance (i));
}
}
}
Weka Development [1]-instances class