List of usage examples for weka.core Instances setRelationName
public void setRelationName(String newName)
From source file:meka.filters.unsupervised.attribute.MekaClassAttributes.java
License:Open Source License
/** * Determines the output format based on the input format and returns * this. In case the output format cannot be returned immediately, i.e., * hasImmediateOutputFormat() returns false, then this method will called * from batchFinished() after the call of preprocess(Instances), in which, * e.g., statistics for the actual processing step can be gathered. * * @param inputFormat the input format to base the output format on * @return the output format * @throws Exception in case the determination goes wrong *//*from w w w .j a va2 s .co m*/ protected Instances determineOutputFormat(Instances inputFormat) throws Exception { int i; int[] indices; StringBuilder order; Instances output; m_AttributeIndices.setUpper(inputFormat.numAttributes() - 1); order = new StringBuilder(); indices = m_AttributeIndices.getSelection(); if (indices.length == 0) throw new WekaException("No attributes defined as class attributes!"); for (i = 0; i < indices.length; i++) { if (i > 0) order.append(","); order.append("" + (indices[i] + 1)); } for (i = 0; i < inputFormat.numAttributes(); i++) { if (m_AttributeIndices.isInRange(i)) continue; order.append(","); order.append("" + (i + 1)); } m_Reorder.setAttributeIndices(order.toString()); m_Reorder.setInputFormat(inputFormat); output = m_Reorder.getOutputFormat(); output.setClassIndex(indices.length); output.setRelationName("-C " + indices.length); return output; }
From source file:meka.gui.explorer.PreprocessTab.java
License:Open Source License
/** * Filters the data with the specified filter. * * @param filter the filter to push the data through * @param newName the new relation name, null if to keep current *///from ww w. jav a 2 s .com protected void filterData(final Filter filter, final String newName) { Runnable run; log("Filtering data: " + OptionUtils.toCommandLine(filter)); run = new Runnable() { @Override public void run() { try { String relName = getData().relationName(); filter.setInputFormat(getData()); Instances filtered = Filter.useFilter(getData(), filter); if (newName == null) filtered.setRelationName(relName); else filtered.setRelationName(newName); getOwner().notifyTabsDataChanged(PreprocessTab.this, filtered); setData(filtered); log("Data filtered successfully!"); } catch (Exception e) { throw new IllegalStateException(e); } } }; start(run); }