Import java. Io .*;
Import WEKA. classifiers .*;
Import WEKA. classifiers. Meta. vote;
Import WEKA. Core. instance;
Import WEKA. Core. instances;
Import WEKA. Core. selectedtag;
Import WEKA. Core. converters. arffloader;
Public class test {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Instances tranins = NULL; // training data
Instances testins = NULL; // Test Data
Classifier cfs1 = NULL; // classifier 1
Classifier cfs2 = NULL; // classifier 2
Classifier cfs3 = NULL; // classifier 3
Classifier [] cfsarray = new classifier [3]; // classifier Array
Try
{
File file = new file ("C: // program files // WEKA-3-6 // data // segment-challenge.arff"); // training data
Arffloader loader = new arffloader ();
Loader. setfile (File );
Tranins = loader. getdataset (); // read data
File = new file ("C: // program files // WEKA-3-6 // data // segment-test.arff"); // Test Data
Loader. setfile (File );
Testins = loader. getdataset ();
Testins. setclassindex (testins. numattributes ()-1); // you can specify the location of a category.
Tranins. setclassindex (tranins. numattributes ()-1 );
Cfs1 = (classifier) class. forname ("WEKA. classifiers. BAYes. naivebayes"). newinstance (); // Algorithm
Cfs2 = (classifier) class. forname ("WEKA. classifiers. Trees. j48"). newinstance ();
Cfs3 = (classifier) class. forname ("WEKA. classifiers. Rules. zeror"). newinstance ();
Cfsarray [0] = cfs1;
Cfsarray [1] = cfs2;
Cfsarray [2] = cfs3;
// Classifier Decision-Making Method
Vote ensemble = new vote ();
Selectedtag tag1 = new selectedtag (vote. majority_voting_rule, vote. tags_rules); // (voting)
Ensemble. setcombinationrule (tag1 );
Ensemble. setclassifiers (cfsarray );
Ensemble. setseed (2); // sets the Random Seed.
Ensemble. buildclassifier (tranins); // train the classifier.
Instance testinst;
Evaluation testingevaluation1 = new evaluation (testins); // class used to detect the classification model
Evaluation testingevaluation2 = new evaluation (testins );
Evaluation testingevaluation3 = new evaluation (testins );
Evaluation testingevaluation4 = new evaluation (testins );
Int length = testins. numinstances ();
// Learn independently
For (INT I = 0; I <length; I ++)
{
Testinst = testins. instance (I );
Testingevaluation1.evaluatemodelonceandrecordprediction (cfs1, testinst );
}
System. Out. println ("classification accuracy rate:" + (1-testingevaluation1.errorrate ()));
For (INT I = 0; I <length; I ++)
{
Testinst = testins. instance (I );
Testingevaluation2.evaluatemodelonceandrecordprediction (cfs2, testinst );
}
System. Out. println ("classification accuracy rate:" + (1-testingevaluation2.errorrate ()));
For (INT I = 0; I <length; I ++)
{
Testinst = testins. instance (I );
Testingevaluation3.evaluatemodelonceandrecordprediction (cfs3, testinst );
}
System. Out. println ("classification accuracy rate:" + (1-testingevaluation3.errorrate ()));
// Integrated Learning
For (INT I = 0; I <length; I ++)
{
Testinst = testins. instance (I );
Testingevaluation4.evaluatemodelonceandrecordprediction (ensemble, testinst );
}
System. Out. println ("classification accuracy rate:" + (1-testingevaluation4.errorrate ()));
}
Catch (exception E)
{
E. printstacktrace ();
}
}
}