⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 removemissingvalues.java

📁 MacroWeka扩展了著名数据挖掘工具weka
💻 JAVA
字号:
package chen.macroweka.filters.unsupervised.instance;

import weka.core.Instance;
import weka.core.Instances;
import weka.core.Utils;
import weka.filters.Filter;
import weka.filters.UnsupervisedFilter;

/**
 * @author anilkpatro
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class RemoveMissingValues extends Filter implements UnsupervisedFilter {
	
	/**
	 * 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
	 * @exception Exception
	 *                if the input format can't be set successfully
	 */
	public boolean setInputFormat(Instances instanceInfo) throws Exception {
		super.setInputFormat(instanceInfo);
		setOutputFormat(instanceInfo);
		return true;
	}

	/**
	 * Signify that this batch of input to the filter is finished. Output() may
	 * now be called to retrieve the filtered instances.
	 * 
	 * @return true if there are instances pending output
	 * @exception IllegalStateException
	 *                if no input structure has been defined
	 */
	public boolean batchFinished() {
		if (getInputFormat() == null) {
			throw new IllegalStateException("No input instance format defined");
		}
		// Push instances for output into output queue
		for (int i = 0; i < getInputFormat().numInstances(); i++) {
			boolean bMissing = false;
			Instance inst = getInputFormat().instance(i);
			for (int j = 0; j < inst.numAttributes(); j++) {
				if (inst.isMissing(j)) {
					bMissing = true;
					break;
				}
			}
			if (!bMissing) {
				push((Instance)getInputFormat().instance(i).copy());
			}
		}
		m_NewBatch = true;
		return (numPendingOutput() != 0);
	}

	public static void main(String[] args) {
		try {
			if (Utils.getFlag('b', args)) {
				Filter.batchFilterFile(new RemoveMissingValues(), args);
			} else {
				Filter.filterFile(new RemoveMissingValues(), args);
			}
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -