Easy, see Batch Filtering
Instances train = ...
The filter is initialized using training data, and then applied to both training and test data.
The problem is that you apply the ReplaceMissingValue filter outside of any processing pipeline, because after writing filtered data, you can no longer distinguish between "real" values ββand "imputed" values. This is why you should do everything you need to do in one pipeline, for example, using FilteredClassifier:
java -classpath weka.jar weka.classifiers.meta.FilteredClassifier -t "training_file_with_missing_values.arff" -T "test_file_with_missing_values.arff" -F weka.filters.unsupervised.attribute.ReplaceMissingValues -W weka.classifiers.functions.MultilayerPerceptron -- -L 0.3 -M 0.2 -H a
In this example, the ReplaceMissingValues ββfilter will be initialized using the training _file_with_missing_values.arff "dataset, then apply the filter to the _file_with_missing_values.arff test " (with training tools on the training set), then train the multilayer perceptron on the filtered training data and predict the class from data.
source share