1. 程式人生 > >weka學習(二) 歸一化處理

weka學習(二) 歸一化處理

/**
 * 歸一化處理
 *
 * @author hao.wei
 */
@Service
public class NormalizeBizImpl implements NormalizeBiz {

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

    @Override
    public Instances normalizeHandle(Instances instances, String[] options) {
        //對資料進行歸一化
        Instances newInstances = null;
        try {
            logger.info("歸一化begin,時間[{}]",new Date());
            Normalize norm = new Normalize();
            if (null != options) {
                // 可以指定資料結果集範圍,不傳為[0,1]
                // String[] options = { "-S", "2.0", "-T", "-1.0" };
                norm.setOptions(options);
            }
            norm.setInputFormat(instances);
            //歸一化關鍵步驟
            newInstances = Filter.useFilter(instances, norm);
            logger.info("歸一化end,時間[{}]",new Date());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return newInstances;
    }
}