Created
November 24, 2014 02:03
-
-
Save dpzmick/a1843a0f056d04ad1aba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import weka.classifiers.Classifier; | |
| import weka.classifiers.Evaluation; | |
| import weka.classifiers.functions.Logistic; | |
| import weka.classifiers.functions.SMO; | |
| import weka.classifiers.functions.MultilayerPerceptron; | |
| import weka.core.Instances; | |
| import weka.core.converters.ConverterUtils.DataSource; | |
| import weka.filters.Filter; | |
| import weka.filters.supervised.instance.Resample; | |
| import weka.filters.unsupervised.attribute.RemoveUseless; | |
| import weka.filters.unsupervised.attribute.RandomProjection; | |
| import java.util.Random; | |
| public class Main2 { | |
| public static void main(String args[]) throws Exception { | |
| DataSource source = new DataSource("/home/zmick2/440/intel/data/train.arff"); | |
| Instances data = source.getDataSet(); | |
| data.setClassIndex(data.numAttributes() - 1); | |
| // do the remove useless thing | |
| RemoveUseless ru = new RemoveUseless(); | |
| ru.setInputFormat(data); | |
| data = Filter.useFilter(data, ru); | |
| // do the random projection thing | |
| RandomProjection rp = new RandomProjection(); | |
| rp.setOptions( new String[]{"-N", "1000"} ); | |
| rp.setInputFormat(data); | |
| data = Filter.useFilter(data, rp); | |
| for (int p : new int[]{2, 6, 100}) { | |
| // set up to resample | |
| Resample resample = new Resample(); | |
| resample.setOptions( new String[]{"-Z", String.valueOf(p)}); | |
| resample.setInputFormat(data); | |
| // run resample | |
| Instances smallerData = Filter.useFilter(data, resample); | |
| for (int i = 0; i < 4; i++) { | |
| Classifier model = null; | |
| String str = ""; | |
| switch (i) { | |
| case 0: | |
| str = "Running logistic\n---"; | |
| model = new Logistic(); | |
| model.setOptions(new String[]{"-M","50"}); | |
| break; | |
| case 1: | |
| str = "Running smo\n---"; | |
| model = new SMO(); | |
| break; | |
| case 2: | |
| str = "Running percept single layer\n---"; | |
| model = new MultilayerPerceptron(); | |
| model.setOptions(new String[]{"-H","0"}); | |
| break; | |
| case 3: | |
| str = "Running percept multi layer\n---"; | |
| model = new MultilayerPerceptron(); | |
| model.setOptions(new String[]{"-H","50", "-N","10"}); | |
| break; | |
| } | |
| // do cross validation | |
| Evaluation eval = new Evaluation(smallerData); | |
| eval.crossValidateModel(model, smallerData, 5, new Random(System.currentTimeMillis())); | |
| System.out.println(str); | |
| System.out.printf("i=%d p=%d\n", i, p); | |
| System.out.println(eval.toSummaryString()); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment