Weka Two-time development Tutorials (Eclipse+weka)
the full name of Weka is the Waikato Intelligent Analytics Environment (Waikato Environment for knowledge analysis), a free, non-commercial, open-source machine learning and data mining software based on the Java environment.
after installing the environment, Weka's download address: http://www.cs.waikato.ac.nz/ml/weka/developer Verstion
Create a new Java project, add a jar package, under the Weka installation directory (Weka.jar and Weka-src.jar)
The following is the test code, the data set used by the weka-3-7 comes with
Package test;
import Java.io.File;
import Weka.classifiers.CheckClassifier;
import Weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.evaluation.*;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.*;
Public class Testweka {
/**
* @param args
*/
Public static void Main (string[] args) {
Instances ins = null;
Classifier cfs = null;
try {
//Read into the Training test sample
File File = new file ("C:\\Program Files\\weka-3-7\\data\\contact-lenses.arff");
Arffloader loader = new Arffloader ();
loader.setfile (file);
ins = Loader.getdataset ();
Ins.setclassindex (Ins.numattributes ()-1);
//Initialize classifier
cfs = (Classifier) class.forname ("Weka.classifiers.bayes.NaiveBayes"). newinstance ();
//Use training samples for classification
cfs.buildclassifier (INS);
//Use test samples to test the learning effect of the classifier
Instance Testinst;
Evaluation testingevaluation = new Evaluation (ins);
int length = Ins.numinstances ();
for (int i = 0; i < length; i++) {
testinst = ins.instance (i);
testingevaluation.evaluatemodelonceandrecordprediction (CFS, testinst);
}
//Print classification results
System.out.println ("The correct rate of classification" + (1-testingevaluation.errorrate ()));
} catch (Exception e) {
e.printstacktrace ();
}
}
}
All normal, the output is: classification of the correct rate 0.9583333333333334