use of meka.filters.unsupervised.attribute.MekaClassAttributes in project dkpro-tc by dkpro.
the class WekaUtils method applyAttributeSelectionFilter.
/**
* Applies a filter to reduce the dimension of attributes and reorders them to be used within
* Meka
*
* @param trainData
* the train data
* @param removeFilter
* remove filter
* @return weka instances
* @throws Exception
* in case of error
*/
public static Instances applyAttributeSelectionFilter(Instances trainData, Remove removeFilter) throws Exception {
// less attributes than should be kept => ignore filter
if (removeFilter == null) {
return trainData;
}
Instances filtered = Filter.useFilter(trainData, removeFilter);
filtered.setClassIndex(trainData.classIndex());
// swap attributes to fit MEKA
MekaClassAttributes attFilter = new MekaClassAttributes();
attFilter.setAttributeIndices(filtered.numAttributes() - trainData.classIndex() + 1 + "-last");
attFilter.setInputFormat(filtered);
filtered = Filter.useFilter(filtered, attFilter);
int newClassindex = filtered.classIndex();
filtered.setRelationName(filtered.relationName().replaceAll("\\-C\\s[\\d]+", "-C " + newClassindex));
return filtered;
}
Aggregations