Java Code Examples for weka.core.Instances#setRelationName()
The following examples show how to use
weka.core.Instances#setRelationName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DD_DTW.java From tsml with GNU General Public License v3.0 | 5 votes |
@Override protected Instances determineOutputFormat(Instances inputFormat) throws Exception { Instances output = new Instances(inputFormat,0); output.deleteAttributeAt(0); output.setRelationName("goreckiDerivative_"+output.relationName()); for(int a = 0; a < output.numAttributes()-1; a++){ output.renameAttribute(a, "derivative_"+a); } return output; }
Example 2
Source File: RemoveType.java From tsml with GNU General Public License v3.0 | 5 votes |
/** * Sets the format of the input instances. * * @param instanceInfo an Instances object containing the input instance * structure (any instances contained in the object are ignored - only the * structure is required). * @return true if the outputFormat may be collected immediately * @throws Exception if the inputFormat can't be set successfully */ public boolean setInputFormat(Instances instanceInfo) throws Exception { super.setInputFormat(instanceInfo); int[] attsToDelete = new int[instanceInfo.numAttributes()]; int numToDelete = 0; for (int i=0; i<instanceInfo.numAttributes(); i++) { if (i == instanceInfo.classIndex()) { if (!m_invert) { continue; // skip class } else { attsToDelete[numToDelete++] = i; // Need to keep the class even if selection is inverted } } if (instanceInfo.attribute(i).type() == m_attTypeToDelete) attsToDelete[numToDelete++] = i; } int[] finalAttsToDelete = new int[numToDelete]; System.arraycopy(attsToDelete, 0, finalAttsToDelete, 0, numToDelete); m_attributeFilter.setAttributeIndicesArray(finalAttsToDelete); m_attributeFilter.setInvertSelection(m_invert); boolean result = m_attributeFilter.setInputFormat(instanceInfo); Instances afOutputFormat = m_attributeFilter.getOutputFormat(); // restore old relation name to hide attribute filter stamp afOutputFormat.setRelationName(instanceInfo.relationName()); setOutputFormat(afOutputFormat); return result; }
Example 3
Source File: MekaClassAttributes.java From meka with GNU General Public License v3.0 | 5 votes |
/** * 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 */ 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; }
Example 4
Source File: RemoveUseless.java From tsml with GNU General Public License v3.0 | 4 votes |
/** * Signify that this batch of input to the filter is finished. * * @return true if there are instances pending output * @throws Exception if no input format defined */ public boolean batchFinished() throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_removeFilter == null) { // establish attributes to remove from first batch Instances toFilter = getInputFormat(); int[] attsToDelete = new int[toFilter.numAttributes()]; int numToDelete = 0; for(int i = 0; i < toFilter.numAttributes(); i++) { if (i==toFilter.classIndex()) continue; // skip class AttributeStats stats = toFilter.attributeStats(i); if (stats.missingCount == toFilter.numInstances()) { attsToDelete[numToDelete++] = i; } else if (stats.distinctCount < 2) { // remove constant attributes attsToDelete[numToDelete++] = i; } else if (toFilter.attribute(i).isNominal()) { // remove nominal attributes that vary too much double variancePercent = (double) stats.distinctCount / (double)(stats.totalCount - stats.missingCount) * 100.0; if (variancePercent > m_maxVariancePercentage) { attsToDelete[numToDelete++] = i; } } } int[] finalAttsToDelete = new int[numToDelete]; System.arraycopy(attsToDelete, 0, finalAttsToDelete, 0, numToDelete); m_removeFilter = new Remove(); m_removeFilter.setAttributeIndicesArray(finalAttsToDelete); m_removeFilter.setInvertSelection(false); m_removeFilter.setInputFormat(toFilter); for (int i = 0; i < toFilter.numInstances(); i++) { m_removeFilter.input(toFilter.instance(i)); } m_removeFilter.batchFinished(); Instance processed; Instances outputDataset = m_removeFilter.getOutputFormat(); // restore old relation name to hide attribute filter stamp outputDataset.setRelationName(toFilter.relationName()); setOutputFormat(outputDataset); while ((processed = m_removeFilter.output()) != null) { processed.setDataset(outputDataset); push(processed); } } flushInput(); m_NewBatch = true; return (numPendingOutput() != 0); }
Example 5
Source File: MLUtils.java From meka with GNU General Public License v3.0 | 2 votes |
/** * Fixes the relation name by adding the "-C" attribute to it if necessary. * * @param data the dataset to fix * @param numClassAtts the number of class attributes (0 for none, >0 for attributes at start, <0 for attributes at end) */ public static void fixRelationName(Instances data, int numClassAtts) { if (data.relationName().indexOf(":") == -1) data.setRelationName(data.relationName() + ": -C " + numClassAtts); }