Weka开发[2]-分类器类
package com.cizito.weka.study;import weka.classifiers.bayes.NaiveBayes;import weka.classifiers.functions.SMO;import weka.classifiers.trees.J48;import weka.core.Instances;import weka.core.converters.ConverterUtils.DataSource;/** * @author zhangwei * */public class ClassifierTest {private Instances m_instances = null;/** * @param args */public static void main(String[] args) throws Exception{ClassifierTest ctest = new ClassifierTest(); ctest.getFileInstances( "D:/ProgramFiles/Weka-3-6/data/contact-lenses.arff"); ctest.classify();} public void getFileInstances( String fileName ) throws Exception { DataSource frData = new DataSource( fileName ); m_instances = frData.getDataSet(); m_instances.setClassIndex( m_instances.numAttributes()-1); } public void classify() throws Exception { //J48 classifier = new J48(); NaiveBayes classifier = new NaiveBayes(); //SMO classifier = new SMO(); classifier.buildClassifier( m_instances ); System.out.println( classifier.classifyInstance( m_instances.instance( 0 ) ) ); } }
?