Instances train = ... // from somewhere Instances test = ... // from somewhere Standardize filter = new Standardize(); filter.setInputFormat(train); // initializing the filter once with training set Instances newTrain = Filter.useFilter(train, filter); // configures the Filter based on train instances and returns filtered instances Instances newTest = Filter.useFilter(test, filter); // create new test se
/** * Input an instance for filtering. Filter requires all * training instances be read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be * collected with output(). * @throws IllegalStateException if no input format has been set. */ public boolean input(Instance instance) throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (m_Means == null) { bufferInput(instance); return false; } else { convertInstance(instance); return true; } }
/** * Main method for testing this class. * * @param argv should contain arguments to the filter: * use -h for help */ public static void main(String [] argv) { runFilter(new Standardize(), argv); } }
m_ClassStdDev = StrictMath.sqrt(instances.variance(instances .classIndex())); m_Filter = new Standardize(); ((Standardize) m_Filter).setIgnoreClass(true); break; default:
protected void fillCovariance() throws Exception { // just center the data or standardize it? if (m_center) { m_centerFilter = new Center(); m_centerFilter.setInputFormat(m_TrainInstances); m_TrainInstances = Filter.useFilter(m_TrainInstances, m_centerFilter); } else { m_standardizeFilter = new Standardize(); m_standardizeFilter.setInputFormat(m_TrainInstances); m_TrainInstances = Filter.useFilter(m_TrainInstances, m_standardizeFilter); } // now compute the covariance matrix m_Correlation = new UpperSymmDenseMatrix(m_NumAttribs); for (int i = 0; i < m_NumAttribs; i++) { for (int j = i; j < m_NumAttribs; j++) { double cov = 0; for (Instance inst: m_TrainInstances) { cov += inst.value(i) * inst.value(j); } cov /= m_TrainInstances.numInstances() - 1; m_Correlation.set(i, j, cov); } } }
m_standardizeFilter.input(tempInst); m_standardizeFilter.batchFinished(); tempInst = m_standardizeFilter.output(); } else { m_centerFilter.input(tempInst);
if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); Instances input = getInputFormat(); m_Means = new double[input.numAttributes()]; m_StdDevs = new double[input.numAttributes()]; convertInstance(input.instance(i)); flushInput(); return (numPendingOutput() != 0);
if (instance.attribute(j).isNumeric() && (!Utils.isMissingValue(vals[j])) && (getInputFormat().classIndex() != j)) { } else { double[] vals = instance.toDoubleArray(); for (int j = 0; j < getInputFormat().numAttributes(); j++) { if (instance.attribute(j).isNumeric() && (!Utils.isMissingValue(vals[j])) && (getInputFormat().classIndex() != j)) { push(inst, false); // No need to copy
m_Filter = new Standardize(); ((Standardize)m_Filter).setIgnoreClass(true); m_Filter.setInputFormat(instances); instances = Filter.useFilter(instances, m_Filter);
protected void fillCovariance() throws Exception { // just center the data or standardize it? if (m_center) { m_centerFilter = new Center(); m_centerFilter.setInputFormat(m_TrainInstances); m_TrainInstances = Filter.useFilter(m_TrainInstances, m_centerFilter); } else { m_standardizeFilter = new Standardize(); m_standardizeFilter.setInputFormat(m_TrainInstances); m_TrainInstances = Filter.useFilter(m_TrainInstances, m_standardizeFilter); } // now compute the covariance matrix m_Correlation = new UpperSymmDenseMatrix(m_NumAttribs); for (int i = 0; i < m_NumAttribs; i++) { for (int j = i; j < m_NumAttribs; j++) { double cov = 0; for (Instance inst: m_TrainInstances) { cov += inst.value(i) * inst.value(j); } cov /= m_TrainInstances.numInstances() - 1; m_Correlation.set(i, j, cov); } } }
/** * Main method for testing this class. * * @param argv should contain arguments to the filter: * use -h for help */ public static void main(String [] argv) { runFilter(new Standardize(), argv); } }
m_standardizeFilter.input(tempInst); m_standardizeFilter.batchFinished(); tempInst = m_standardizeFilter.output(); } else { m_centerFilter.input(tempInst);
if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); Instances input = getInputFormat(); m_Means = new double[input.numAttributes()]; m_StdDevs = new double[input.numAttributes()]; convertInstance(input.instance(i)); flushInput(); return (numPendingOutput() != 0);
if (instance.attribute(j).isNumeric() && (!Utils.isMissingValue(vals[j])) && (getInputFormat().classIndex() != j)) { } else { double[] vals = instance.toDoubleArray(); for (int j = 0; j < getInputFormat().numAttributes(); j++) { if (instance.attribute(j).isNumeric() && (!Utils.isMissingValue(vals[j])) && (getInputFormat().classIndex() != j)) { push(inst, false); // No need to copy
Instances train = ... // from somewhere Instances test = ... // from somewhere Standardize filter = new Standardize(); filter.setInputFormat(train); // initializing the filter once with training set Instances newTrain = Filter.useFilter(train, filter); // configures the Filter based on train instances and returns filtered instances Instances newTest = Filter.useFilter(test, filter); // create new test set
m_Filter = new Standardize(); ((Standardize)m_Filter).setIgnoreClass(true); m_Filter.setInputFormat(instances); instances = Filter.useFilter(instances, m_Filter);
m_trainInstances = Filter.useFilter(m_trainInstances, m_centerFilter); } else { m_standardizeFilter = new Standardize(); m_standardizeFilter.setInputFormat(m_trainInstances); m_trainInstances = Filter.useFilter(m_trainInstances, m_standardizeFilter);
m_standardizeFilter.input(tempInst); m_standardizeFilter.batchFinished(); tempInst = m_standardizeFilter.output(); } else { m_centerFilter.input(tempInst);
/** * Input an instance for filtering. Filter requires all * training instances be read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be * collected with output(). * @throws IllegalStateException if no input format has been set. */ public boolean input(Instance instance) throws Exception { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (m_Means == null) { bufferInput(instance); return false; } else { convertInstance(instance); return true; } }
/** Creates an example Standardize */ public Filter getFilter() { Standardize f = new Standardize(); return f; }