0

I need to implement a Weka classifier that standaridizes the input data before processing. I use the following code for this:

private Filter standardize = new Standardize();
...
public void buildClassifier(Instances instances) throws Exception {
    if (this.stdAtt) {
        this.standardize.setInputFormat(instances);
        instances = Filter.useFilter(instances, this.standardize);
    }
    ....
}

Now, to classify a single Instance, I also need to standardize it before actually classifying using the same Standardize filter. But Filter.useFilter only accepts Instances as an argument - and not an Instance.

public double classifyInstance(Instance instance) throws Exception {
    if (this.stdAtt) {
        // standardize instance before processing
    }
    return super.classifyInstance(instance);
}

How can I do it? Or should I implement my own standardizer?

  • "Standardizing" basically means "divide by the standard deviation and subtract the mean". So standardizing a *single instance* does not make any sense. If you want to apply the same operation to the single instance that was also applied to the initial instances, then you'd probably have to compute the mean and stdDev manually, so that you can later do the computation to the single instance (I'm not aware of a built-in way to do this, but would have to do some research). Note, however: The mean/stdDev would have been *different* if the given instance had already been part of the initial data! – Marco13 May 13 '18 at 21:51
  • I'm not very familiar with Weka's Java API but I think the appropriate way to implement the standardisation would be to create a FilteredClassifier using the Standardize filter. I think you should then be able to use the trained classifier for prediction and it will apply the same transformation to the instance being predicted that was learned from the training set. – nekomatic May 15 '18 at 10:43

0 Answers0