Java examples for Machine Learning AI:weka
Weka Classifier Setting
import java.io.File; import weka.classifiers.evaluation.Evaluation; import weka.classifiers.trees.J48; import weka.core.Debug.Random; import weka.core.Instances; import weka.core.Utils; import weka.core.converters.ArffLoader; import weka.core.converters.ConverterUtils.DataSource; public class WekaClassifierSetting { public static void main(String[] args) throws Exception { File inputFile = new File( "bank-train.arff"); atf.setFile(inputFile);/*from w ww. j av a2 s. c o m*/ Instances instancesTrain = atf.getDataSet(); "bank-test.arff"); Instances instancesTest = source.getDataSet(); instancesTest.setClassIndex(instancesTest.numAttributes() - 1); String[] options = Utils.splitOptions("-C 0.25 -M 2"); classifier.setOptions(options); classifier.buildClassifier(instancesTrain); Evaluation eval = new Evaluation(instancesTrain); eval.crossValidateModel(classifier, instancesTrain, 10, new Random( 1)); System.out.println(eval.errorRate()); } }