📄 numericcleaner.java
字号:
* this. In case the output format cannot be returned immediately, i.e., * immediateOutputFormat() returns false, then this method will be called * from batchFinished(). * * @param inputFormat the input format to base the output format on * @return the output format * @throws Exception in case the determination goes wrong * @see #hasImmediateOutputFormat() * @see #batchFinished() */ protected Instances determineOutputFormat(Instances inputFormat) throws Exception { m_Cols.setUpper(inputFormat.numAttributes() - 1); return new Instances(inputFormat); } /** * 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 */ protected Instance process(Instance instance) throws Exception { Instance result; int i; double val; double factor; result = (Instance) instance.copy(); if (m_Decimals > -1) factor = StrictMath.pow(10, m_Decimals); else factor = 1; for (i = 0; i < result.numAttributes(); i++) { // only numeric attributes if (!result.attribute(i).isNumeric()) continue; // out of range? if (!m_Cols.isInRange(i)) continue; // skip class? if ( (result.classIndex() == i) && (!m_IncludeClass) ) continue; // too small? if (result.value(i) < m_MinThreshold) { if (getDebug()) System.out.println("Too small: " + result.value(i) + " -> " + m_MinDefault); result.setValue(i, m_MinDefault); } // too big? else if (result.value(i) > m_MaxThreshold) { if (getDebug()) System.out.println("Too big: " + result.value(i) + " -> " + m_MaxDefault); result.setValue(i, m_MaxDefault); } // too close? else if ( (result.value(i) - m_CloseTo < m_CloseToTolerance) && (m_CloseTo - result.value(i) < m_CloseToTolerance) && (result.value(i) != m_CloseTo) ) { if (getDebug()) System.out.println("Too close: " + result.value(i) + " -> " + m_CloseToDefault); result.setValue(i, m_CloseToDefault); } // decimals? if (m_Decimals > -1) { val = result.value(i); val = StrictMath.round(val * factor) / factor; result.setValue(i, val); } } return result; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String minThresholdTipText() { return "The minimum threshold below values are replaced by a default."; } /** * Get the minimum threshold. * * @return the minimum threshold. */ public double getMinThreshold() { return m_MinThreshold; } /** * Set the minimum threshold. * * @param value the minimum threshold to use. */ public void setMinThreshold(double value) { m_MinThreshold = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String minDefaultTipText() { return "The default value to replace values that are below the minimum threshold."; } /** * Get the minimum default. * * @return the minimum default. */ public double getMinDefault() { return m_MinDefault; } /** * Set the minimum default. * * @param value the minimum default to use. */ public void setMinDefault(double value) { m_MinDefault = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String maxThresholdTipText() { return "The maximum threshold above values are replaced by a default."; } /** * Get the maximum threshold. * * @return the maximum threshold. */ public double getMaxThreshold() { return m_MaxThreshold; } /** * Set the maximum threshold. * * @param value the maximum threshold to use. */ public void setMaxThreshold(double value) { m_MaxThreshold = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String maxDefaultTipText() { return "The default value to replace values that are above the maximum threshold."; } /** * Get the maximum default. * * @return the maximum default. */ public double getMaxDefault() { return m_MaxDefault; } /** * Set the naximum default. * * @param value the maximum default to use. */ public void setMaxDefault(double value) { m_MaxDefault = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String closeToTipText() { return "The number values are checked for whether they are too close to " + "and get replaced by a default."; } /** * Get the "close to" number. * * @return the "close to" number. */ public double getCloseTo() { return m_CloseTo; } /** * Set the "close to" number. * * @param value the number to use for checking closeness. */ public void setCloseTo(double value) { m_CloseTo = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String closeToDefaultTipText() { return "The default value to replace values with that are too close."; } /** * Get the "close to" default. * * @return the "close to" default. */ public double getCloseToDefault() { return m_CloseToDefault; } /** * Set the "close to" default. * * @param value the "close to" default to use. */ public void setCloseToDefault(double value) { m_CloseToDefault = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String closeToToleranceTipText() { return "The value below which values are considered close to."; } /** * Get the "close to" Tolerance. * * @return the "close to" Tolerance. */ public double getCloseToTolerance() { return m_CloseToTolerance; } /** * Set the "close to" Tolerance. * * @param value the "close to" Tolerance to use. */ public void setCloseToTolerance(double value) { m_CloseToTolerance = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String attributeIndicesTipText() { return "The selection of columns to use in the cleansing processs, first and last are valid indices."; } /** * Gets the selection of the columns, e.g., first-last or first-3,5-last * * @return the selected indices */ public String getAttributeIndices() { return m_Cols.getRanges(); } /** * Sets the columns to use, e.g., first-last or first-3,5-last * * @param value the columns to use */ public void setAttributeIndices(String value) { m_Cols.setRanges(value); } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String invertSelectionTipText() { return "If enabled the selection of the columns is inverted."; } /** * Gets whether the selection of the columns is inverted * * @return true if the selection is inverted */ public boolean getInvertSelection() { return m_Cols.getInvert(); } /** * Sets whether the selection of the indices is inverted or not * * @param value the new invert setting */ public void setInvertSelection(boolean value) { m_Cols.setInvert(value); } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String includeClassTipText() { return "If disabled, the class attribute will be always left out of the cleaning process."; } /** * Gets whether the class is included in the cleaning process or always * skipped. * * @return true if the class can be considered for cleaning. */ public boolean getIncludeClass() { return m_IncludeClass; } /** * Sets whether the class can be cleaned, too. * * @param value true if the class can be cleansed, too */ public void setIncludeClass(boolean value) { m_IncludeClass = value; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String decimalsTipText() { return "The number of decimals to round to, -1 means no rounding at all."; } /** * Get the number of decimals to round to. * * @return the number of decimals. */ public int getDecimals() { return m_Decimals; } /** * Set the number of decimals to round to. * * @param value the number of decimals. */ public void setDecimals(int value) { m_Decimals = value; } /** * Runs the filter from commandline, use "-h" to see all options. * * @param args the commandline options for the filter */ public static void main(String[] args) { runFilter(new NumericCleaner(), args); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -