/** * reduce the dimensionality of a single instance to include only those * attributes chosen by the last run of attribute selection. * * @param in the instance to be reduced * @return a dimensionality reduced instance * @exception Exception if the instance can't be reduced */ public Instance reduceDimensionality(Instance in) throws Exception { if (m_attributeFilter == null) { throw new Exception("No feature selection has been performed yet!"); } if (m_transformer != null) { in = m_transformer.convertInstance(in); } m_attributeFilter.input(in); m_attributeFilter.batchFinished(); Instance result = m_attributeFilter.output(); return result; }
/** * reduce the dimensionality of a single instance to include only those * attributes chosen by the last run of attribute selection. * * @param in the instance to be reduced * @return a dimensionality reduced instance * @exception Exception if the instance can't be reduced */ public Instance reduceDimensionality(Instance in) throws Exception { if (m_attributeFilter == null) { throw new Exception("No feature selection has been performed yet!"); } if (m_transformer != null) { in = m_transformer.convertInstance(in); } m_attributeFilter.input(in); m_attributeFilter.batchFinished(); Instance result = m_attributeFilter.output(); return result; }
/** * reduce the dimensionality of a set of instances to include only those * attributes chosen by the last run of attribute selection. * * @param in the instances to be reduced * @return a dimensionality reduced set of instances * @exception Exception if the instances can't be reduced */ public Instances reduceDimensionality(Instances in) throws Exception { if (m_attributeFilter == null) { throw new Exception("No feature selection has been performed yet!"); } if (m_transformer != null) { Instances transformed = new Instances(m_transformer.transformedHeader(), in.numInstances()); for (int i = 0; i < in.numInstances(); i++) { transformed.add(m_transformer.convertInstance(in.instance(i))); } return Filter.useFilter(transformed, m_attributeFilter); } return Filter.useFilter(in, m_attributeFilter); }
/** * reduce the dimensionality of a set of instances to include only those * attributes chosen by the last run of attribute selection. * * @param in the instances to be reduced * @return a dimensionality reduced set of instances * @exception Exception if the instances can't be reduced */ public Instances reduceDimensionality(Instances in) throws Exception { if (m_attributeFilter == null) { throw new Exception("No feature selection has been performed yet!"); } if (m_transformer != null) { Instances transformed = new Instances(m_transformer.transformedHeader(), in.numInstances()); for (int i = 0; i < in.numInstances(); i++) { transformed.add(m_transformer.convertInstance(in.instance(i))); } return Filter.useFilter(transformed, m_attributeFilter); } return Filter.useFilter(in, m_attributeFilter); }
/** * Convert a single instance over. Selected attributes only are transfered. * The converted instance is added to the end of the output queue. * * @param instance the instance to convert * @throws Exception if something goes wrong */ protected void convertInstance(Instance instance) throws Exception { double[] newVals = new double[getOutputFormat().numAttributes()]; if (m_ASEvaluator instanceof AttributeTransformer) { Instance tempInstance = ((AttributeTransformer) m_ASEvaluator).convertInstance(instance); for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; newVals[i] = tempInstance.value(current); } } else { for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; newVals[i] = instance.value(current); } } if (instance instanceof SparseInstance) { push(new SparseInstance(instance.weight(), newVals)); } else { push(new DenseInstance(instance.weight(), newVals)); } }
/** * Convert a single instance over. Selected attributes only are transfered. * The converted instance is added to the end of the output queue. * * @param instance the instance to convert * @throws Exception if something goes wrong */ protected void convertInstance(Instance instance) throws Exception { double[] newVals = new double[getOutputFormat().numAttributes()]; if (m_ASEvaluator instanceof AttributeTransformer) { Instance tempInstance = ((AttributeTransformer) m_ASEvaluator).convertInstance(instance); for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; newVals[i] = tempInstance.value(current); } } else { for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; newVals[i] = instance.value(current); } } if (instance instanceof SparseInstance) { push(new SparseInstance(instance.weight(), newVals)); } else { push(new DenseInstance(instance.weight(), newVals)); } }
new Instances(transformer.transformedHeader(), data.numInstances()); for (int i = 0; i < data.numInstances(); i++) { reduced.add(transformer.convertInstance(data.instance(i)));
new Instances(transformer.transformedHeader(), data.numInstances()); for (int i = 0; i < data.numInstances(); i++) { reduced.add(transformer.convertInstance(data.instance(i)));