/** * Remove Indices - Remove attribute indices 'indices' from 'D'. * @param D Dataset * @param indices attribute indices to remove/keep * @param inv if true, then keep 'indices' * @return New dataset with 'indices' removed. */ public static Instances remove(Instances D, int indices[], boolean inv) throws Exception { Remove remove = new Remove(); remove.setAttributeIndicesArray(indices); remove.setInvertSelection(inv); remove.setInputFormat(D); return Filter.useFilter(D, remove); }
/** * Returns a new set of instances either only with the labels (labels = true) or * only the features (labels = false) * * @param inst The input instances. * @param labels Return labels (true) or features (false) */ protected Instances extractPart(Instances inst, boolean labels) throws Exception{ //TODO Maybe alreade exists somewhere in Meka? Remove remove = new Remove(); remove.setAttributeIndices("first-"+(inst.classIndex())); remove.setInvertSelection(labels); remove.setInputFormat(inst); return Filter.useFilter(inst, remove); }
/** * reduce the dimensionality of a single instance to include only those * attributes chosen by the last run of attribute selection. * * @param in the instance to be reduced * @return a dimensionality reduced instance * @exception Exception if the instance can't be reduced */ public Instance reduceDimensionality(Instance in) throws Exception { if (m_attributeFilter == null) { throw new Exception("No feature selection has been performed yet!"); } if (m_transformer != null) { in = m_transformer.convertInstance(in); } m_attributeFilter.input(in); m_attributeFilter.batchFinished(); Instance result = m_attributeFilter.output(); return result; }
/** * Default constructor: need to set up Remove filter. */ public FilteredDistance() { m_Remove.setInvertSelection(true); m_Remove.setAttributeIndices("first-last"); }
/** * processes the given instance (may change the provided instance) and returns * the modified version. * * @param instance the instance to process * @return the modified data * @throws Exception in case the processing goes wrong */ @Override protected Instance process(Instance instance) throws Exception { m_Remove.input(instance); return m_Remove.output(); }
/** * Remove Indices - Remove ALL labels (assume they are the first L attributes) from D. * @param D Dataset * @param L number of labels * @return New dataset with labels removed. */ public static Instances removeLabels(Instances D, int L) throws Exception { Remove remove = new Remove(); remove.setAttributeIndices("1-"+L); remove.setInputFormat(D); return Filter.useFilter(D, remove); }
Remove removeClass = new Remove(); removeClass.setAttributeIndices("" + theClass); removeClass.setInvertSelection(false); removeClass.setInputFormat(train); if (updateable) { Instances clusterTrain = Filter.useFilter(train, removeClass); while (source.hasMoreElements(train)) { inst = source.nextElement(train); removeClass.input(inst); removeClass.batchFinished(); Instance clusterTrainInst = removeClass.output(); ((UpdateableClusterer) clusterer).updateClusterer(clusterTrainInst);
System.arraycopy(attsToDelete, 0, finalAttsToDelete, 0, numToDelete); m_removeFilter = new Remove(); m_removeFilter.setAttributeIndicesArray(finalAttsToDelete); m_removeFilter.setInvertSelection(false); m_removeFilter.setInputFormat(toFilter); m_removeFilter.input(toFilter.instance(i)); m_removeFilter.batchFinished(); Instances outputDataset = m_removeFilter.getOutputFormat(); while ((processed = m_removeFilter.output()) != null) { processed.setDataset(outputDataset); push(processed, false); // No need to copy
Remove delTransform = new Remove(); delTransform.setInvertSelection(true); delTransform.setAttributeIndicesArray(featArray); delTransform.setInputFormat(trainCopy); delTransform.input(testCopy); testCopy = delTransform.output();
/** * Removes the currently selected attributes. */ protected void removeAttributes() { int[] indices; Remove remove; getOwner().addUndoPoint(); indices = m_PanelAttributes.getSelectedAttributes(); remove = new Remove(); remove.setAttributeIndicesArray(indices); filterData(remove, null); }
/** Creates a specialized Remove */ public Filter getFilter(String rangelist) { Remove af = new Remove(); af.setAttributeIndices(rangelist); return af; }
/** * Removes the labels from a set of instances * * @param dataSet a multi-label dataset * @param labelIndices the indices of the labels * @return the transformed dataset * @throws Exception */ public static Instances transformInstances(Instances dataSet, int[] labelIndices) throws Exception { Remove remove = new Remove(); remove.setAttributeIndicesArray(labelIndices); remove.setInputFormat(dataSet); Instances result = Filter.useFilter(dataSet, remove); return result; }
/** * filters all attributes that should be ignored * * @param data the data to filter * @return the filtered data * @throws Exception if filtering fails */ protected Instances removeIgnored(Instances data) throws Exception { Instances result = data; if (m_ignoreAttributesRange != null || data.classIndex() >= 0) { result = new Instances(data); m_removeAttributes = new Remove(); String rangeString = ""; if (m_ignoreAttributesRange != null) { rangeString += m_ignoreAttributesRange.getRanges(); } if (data.classIndex() >= 0) { if (rangeString.length() > 0) { rangeString += "," + (data.classIndex() + 1); } else { rangeString = "" + (data.classIndex() + 1); } } ((Remove) m_removeAttributes).setAttributeIndices(rangeString); ((Remove) m_removeAttributes).setInvertSelection(false); m_removeAttributes.setInputFormat(data); result = Filter.useFilter(data, m_removeAttributes); } return result; }
/** * Sets whether the matching sense of attribute indices is inverted or not. * * @param value if true the matching sense is inverted */ public void setInvertSelection(boolean value) { m_Remove.setInvertSelection(!value); }
/** * Sets the range of attributes to use in the calculation of the distance. The * indices start from 1, 'first' and 'last' are valid as well. E.g.: * first-3,5,6-last * * @param value the new attribute index range */ public void setAttributeIndices(String value) { m_Remove.setAttributeIndices(value); }
// Untested Java, I use Weka through JRuby NaiveBayes naiveBayes = new NaiveBayes(); Remove remove = new Remove(); remove.setOptions(Utils.splitOptions("-R 1-2")); FilteredClassifier model = new FilteredClassifier(naiveBayes, remove); // Use model to classify as normal
/** * Returns the Capabilities of this filter. * * @return the capabilities of this object * @see Capabilities */ @Override public Capabilities getCapabilities() { Capabilities result; result = new Remove().getCapabilities(); result.setOwner(this); return result; }
/** * Sets the instances. * * @param insts the instances to use */ public void setInstances(Instances insts) { try { m_Remove.setInputFormat(insts); Instances reducedInstances = Filter.useFilter(insts, m_Remove); m_Filter.setInputFormat(reducedInstances); m_Distance.setInstances(Filter.useFilter(reducedInstances, m_Filter)); } catch (Exception e) { e.printStackTrace(); } }
/** * Output an instance after filtering and remove from the output queue. * * @return the instance that has most recently been filtered (or null if the * queue is empty). */ @Override public Instance output() { return m_attributeFilter.output(); }