1. 程式人生 > >weka學習(五)去除重複值

weka學習(五)去除重複值

**
 * @author hao.wei
 * @2018/9/17
 * @desc
 */
@Service
public class DuplicatesPreprocessImpl implements DuplicatesPreprocess {

    private static final Logger logger = LoggerFactory.getLogger(DuplicatesPreprocessImpl.class);


    /**
     * 去除重複值
     * @param instances
     * @para delPositions 要去除的屬性 索引
     * @return
     */
    @Override
    public Instances removeDuplicates(Instances instances,Integer...delPositions) {
        Instances result = null;
        try{
            for (Integer position : delPositions ) {
                instances.deleteAttributeAt(position);
            }
            if(instances.classIndex() == -1) {
                instances.setClassIndex(instances.numAttributes() - 1);
            }
            RemoveDuplicates removeDuplicates = new RemoveDuplicates();
            removeDuplicates.setInputFormat(instances);
            result = Filter.useFilter(instances, removeDuplicates);
        }catch (Exception e) {
            logger.error("去除重複值異常",e);
            //throw new BizException();
        }
        return result;
    }
}