/** * Gets the classifier specification string, which contains the class name of the classifier and * any options to the classifier * * @param index the index of the classifier string to retrieve, starting from 0. * @return the classifier string, or the empty string if no classifier has been assigned (or the * index given is out of range). */ protected String getClassifierSpec(int index) { if (m_Classifiers.length < index) { return ""; } Classifier c = getClassifier(index); return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) c).getOptions()); }
/** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector newVector = new Vector(7); newVector.addElement( new Option( "\tThe index of the class attribute.\n" + "\t(default last)", "c", 1, "-c <class index>")); newVector.addElement( new Option( "\tThe name of the arff file used for the decomposition.", "t", 1, "-t <name of arff file>")); newVector.addElement( new Option( "\tThe number of instances placed in the training pool.\n" + "\tThe remainder will be used for testing. (default 100)", "T", 1, "-T <training pool size>")); newVector.addElement(new Option("\tThe random number seed used.", "s", 1, "-s <seed>")); newVector.addElement( new Option( "\tThe number of training repetitions used.\n" + "\t(default 50)", "x", 1, "-x <num>")); newVector.addElement(new Option("\tTurn on debugging output.", "D", 0, "-D")); newVector.addElement( new Option( "\tFull class name of the learner used in the decomposition.\n" + "\teg: weka.classifiers.bayes.NaiveBayes", "W", 1, "-W <classifier class name>")); if ((m_Classifier != null) && (m_Classifier instanceof OptionHandler)) { newVector.addElement( new Option( "", "", 0, "\nOptions specific to learner " + m_Classifier.getClass().getName() + ":")); Enumeration enu = ((OptionHandler) m_Classifier).listOptions(); while (enu.hasMoreElements()) { newVector.addElement(enu.nextElement()); } } return newVector.elements(); }
/** * Test a feature collection where each feature will be in it's own bin. * * <p>Creates a feature collection with five features 1-5. Then uses the quantile function to put * these features in 5 bins. Each bin should have a single feature. * * @throws Exception */ public void testSingleBin() throws Exception { // create a feature collection with five features values 1-5 SimpleFeatureType dataType = DataUtilities.createType("classification.test1", "id:0,value:int"); int iVal[] = new int[] {1, 2, 3, 4, 5}; SimpleFeature[] myfeatures = new SimpleFeature[iVal.length]; for (int i = 0; i < iVal.length; i++) { myfeatures[i] = SimpleFeatureBuilder.build( dataType, new Object[] {new Integer(i + 1), new Integer(iVal[i])}, "classification.test1" + (i + 1)); } MemoryDataStore store = new MemoryDataStore(); store.createSchema(dataType); store.addFeatures(myfeatures); FeatureCollection<SimpleFeatureType, SimpleFeature> myFeatureCollection = store.getFeatureSource("test1").getFeatures(); // run the quantile function org.opengis.filter.expression.Expression function = ff.function("Quantile", ff.property("value"), ff.literal(5)); Classifier classifier = (Classifier) function.evaluate(myFeatureCollection); // verify the results assertNotNull(classifier); assertEquals(classifier.getClass(), RangedClassifier.class); RangedClassifier range = (RangedClassifier) classifier; assertEquals(5, range.getSize()); for (int i = 0; i < 5; i++) { assertTrue(i + 1 == ((Number) range.getMin(i)).doubleValue()); if (i != 4) { assertTrue(i + 2 == ((Number) range.getMax(i)).doubleValue()); assertEquals((i + 1) + ".." + (i + 2), range.getTitle(i)); } else { assertTrue(i + 1 == ((Number) range.getMax(i)).doubleValue()); assertEquals((i + 1) + ".." + (i + 1), range.getTitle(i)); } } }