weka.filters.Filter类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中weka.filters.Filter类的一些代码示例,展示了Filter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Filter类的具体详情如下:
包路径:weka.filters.Filter
类名称:Filter

Filter介绍

[英]An abstract class for instance filters: objects that take instances as input, carry out some transformation on the instance and then output the instance. The method implementations in this class assume that most of the work will be done in the methods overridden by subclasses.

A simple example of filter use. This example doesn't remove instances from the output queue until all instances have been input, so has higher memory consumption than an approach that uses output instances as they are made available:

``

Filter filter = ..some type of filter.. 
Instances instances = ..some instances.. 
for (int i = 0; i < data.numInstances(); i++) { 
filter.input(data.instance(i)); 
} 
filter.batchFinished(); 
Instances newData = filter.outputFormat(); 
Instance processed; 
while ((processed = filter.output()) != null) { 
newData.add(processed); 
} 
..do something with newData..

``
[中]

代码示例

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns a numeric version of a set of instances. All nominal attributes are
 * replaced by binary ones, and the class variable is replaced by a
 * pseudo-class variable that is used by LogitBoost.
 */
@Override
protected Instances getNumericData(Instances train) throws Exception {
 Instances filteredData = Filter.useFilter(train, m_nominalToBinary);
 return super.getNumericData(filteredData);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {
 super.setInputFormat(instanceInfo);
 return false;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Override
public Capabilities getCapabilities(Instances data) {
 return m_delegate.getCapabilities(data);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

/**
 * Apply the filters (if any) for this map task to the supplied instance
 *
 * @param original the instance in the original space
 * @return a filtered instance
 * @throws Exception if a problem occurs
 */
public Instance applyFilters(Instance original) throws Exception {
 Instance result = original;
 if (m_finalFullPreprocess != null) {
  ((Filter) m_finalFullPreprocess).input(result);
  result = ((Filter) m_finalFullPreprocess).output();
 }
 return result;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/SMOTE

/**
 * 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 input format can't be set successfully
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {
 super.setInputFormat(instanceInfo);
 super.setOutputFormat(instanceInfo);
 return true;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Classifies a given instance after filtering.
 * 
 * @param instance the instance to be classified
 * @return the class distribution for the given instance
 * @throws Exception if instance could not be classified successfully
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 if (m_Filter.numPendingOutput() > 0) {
  throw new Exception("Filter output queue not empty!");
 }
 if (!m_Filter.input(instance)) {
  throw new Exception(
   "Filter didn't make the test instance immediately available!");
 }
 m_Filter.batchFinished();
 Instance newInstance = m_Filter.output();
 return m_Clusterer.distributionForInstance(newInstance);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * 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();
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Override
public double[] distributionForInstance(Instance inst) throws Exception {
 if (!getPreConstructedFilter().input(inst)) {
  throw new Exception("Filter did not make instance available immediately!");
 }
 getPreConstructedFilter().batchFinished();
 Instance testI = getPreConstructedFilter().output();
 return getClassifier().distributionForInstance(testI);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

/**
 * Apply the filters (if any) setup for this map task to the supplied
 * instances
 *
 * @param toApplyTo the instances to filer
 * @return a filtered set of instances
 * @throws Exception if a problem occurs
 */
public Instances applyFilters(Instances toApplyTo) throws Exception {
 Instances result = toApplyTo;
 if (m_finalFullPreprocess != null) {
  result =
   new Instances(((Filter) m_finalFullPreprocess).getOutputFormat(), 0);
  for (int i = 0; i < toApplyTo.numInstances(); i++) {
   ((Filter) m_finalFullPreprocess).input(toApplyTo.instance(i));
   Instance processed = ((Filter) m_finalFullPreprocess).output();
   result.add(processed);
  }
 }
 return result;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Override
public boolean batchFinished() throws Exception {
 return getBaseFilter().batchFinished();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Override
public boolean input(Instance inst) throws Exception {
 return m_delegate.input(inst);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Override
public Instance output() {
 Instance outInst = m_delegate.output();
 if (m_hasStringAtts && outInst != null) {
  for (int i = 0; i < outInst.dataset().numAttributes(); i++) {
   if (outInst.dataset().attribute(i).isString() && !outInst.isMissing(i)) {
    String val = outInst.stringValue(i);
    outInst.attribute(i).setStringValue(val);
    outInst.setValue(i, 0);
   }
  }
 }
 return outInst;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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();
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Update the distance function (if necessary) for the newly added instance.
 * 
 * @param ins the instance to add
 */
public void update(Instance ins) {
 try {
  m_Remove.input(ins);
  m_Filter.input(m_Remove.output());
  m_Distance.update(m_Filter.output());
 } catch (Exception e) {
  e.printStackTrace();
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Classifies a given instance after filtering.
 * 
 * @param instance the instance to be classified
 * @return the class distribution for the given instance
 * @throws Exception if instance could not be classified successfully
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 if (m_Filter.numPendingOutput() > 0) {
  throw new Exception("Filter output queue not empty!");
 }
 if (!m_Filter.input(instance)) {
  throw new Exception(
   "Filter didn't make the test instance immediately available!");
 }
 m_Filter.batchFinished();
 Instance newInstance = m_Filter.output();
 return m_Clusterer.distributionForInstance(newInstance);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Filters an instance.
 */
protected Instance filterInstance(Instance inst) throws Exception {
 if (!m_checksTurnedOff) {
  m_Missing.input(inst);
  m_Missing.batchFinished();
  inst = m_Missing.output();
 }
 if (m_NominalToBinary != null) {
  m_NominalToBinary.input(inst);
  m_NominalToBinary.batchFinished();
  inst = m_NominalToBinary.output();
 }
 if (m_Filter != null) {
  m_Filter.input(inst);
  m_Filter.batchFinished();
  inst = m_Filter.output();
 }
 return inst;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Signify that this batch of input to the filter is finished. If the filter
 * requires all instances prior to filtering, output() may now be called to
 * retrieve the filtered instances. Any subsequent instances filtered should
 * be filtered based on setting obtained from the first batch (unless the
 * setInputFormat has been re-assigned or new options have been set).
 * 
 * @return true if there are instances pending output
 * @throws IllegalStateException if no input format has been set.
 */
@Override
public boolean batchFinished() throws Exception {
 super.batchFinished();
 for (int i = 0; i > getFilters().length; i++) {
  getFilter(i).batchFinished();
 }
 return (numPendingOutput() != 0);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Returns a numeric version of a set of instances. All nominal attributes are
 * replaced by binary ones, and the class variable is replaced by a
 * pseudo-class variable that is used by LogitBoost.
 */
@Override
protected Instances getNumericData(Instances train) throws Exception {
 Instances filteredData = Filter.useFilter(train, m_nominalToBinary);
 return super.getNumericData(filteredData);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {
 super.setInputFormat(instanceInfo);
 m_removeFilter = null;
 return false;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Update the distance function (if necessary) for the newly added instance.
 * 
 * @param ins the instance to add
 */
public void update(Instance ins) {
 try {
  m_Remove.input(ins);
  m_Filter.input(m_Remove.output());
  m_Distance.update(m_Filter.output());
 } catch (Exception e) {
  e.printStackTrace();
 }
}

相关文章