Example usage for weka.filters.supervised.instance SMOTE setOptions

List of usage examples for weka.filters.supervised.instance SMOTE setOptions

Introduction

In this page you can find the example usage for weka.filters.supervised.instance SMOTE setOptions.

Prototype

public void setOptions(String[] options) throws Exception 

Source Link

Document

Parses a given list of options.

Usage

From source file:mao.datamining.DataSetPair.java

private void createSampleDataSets() {
    try {/*w  w w .  j a v a  2 s .c  om*/
        //reload the new data from new arff file: Main.OrangeProcessedDSHome+"/afterRemoveRows.arff"
        Instances newData = ConverterUtils.DataSource
                .read(Main.OrangeProcessedDSHome + "/afterRemoveRows2.arff");
        newData.setClassIndex(newData.numAttributes() - 1);
        //create none sample file
        //            Main.logging("== New Data After Doing Nothing, waiting for CostMatrix: ===\n" + newData.toSummaryString());
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream(Main.OrangeProcessedDSHome + "/afterNoneSampling.arff")))) {
            writer.write(newData.toString());
        }
        //create under sample file
        //            System.out.println("Under Samplessssssssssssssssssssssssssssssssssssss");
        SpreadSubsample underSampleFilter = new weka.filters.supervised.instance.SpreadSubsample();
        underSampleFilter.setInputFormat(newData);
        String underOptionsClone[] = new String[underSampleFilterOptions.length];
        System.arraycopy(underSampleFilterOptions, 0, underOptionsClone, 0, underSampleFilterOptions.length);
        underSampleFilter.setOptions(underOptionsClone);
        Instances underNewData = Filter.useFilter(newData, underSampleFilter);

        //            Main.logging("== New Data After Under Sampling: ===\n" + underNewData.toSummaryString());
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream(Main.OrangeProcessedDSHome + "/afterUnderSampling.arff")))) {
            writer.write(underNewData.toString());
        }
        //create over sample file
        //            System.out.println("Over Samplessssssssssssssssssssssssssssssssssssss");
        //weka.filters.supervised.instance.SMOTE -C 0 -K 5 -P 1000.0 -S 1 smoteOptions
        SMOTE smote = new weka.filters.supervised.instance.SMOTE();
        smote.setInputFormat(newData);
        String overOptionsClone[] = new String[overSampleSmoteOptions.length];
        System.arraycopy(overSampleSmoteOptions, 0, overOptionsClone, 0, overSampleSmoteOptions.length);
        smote.setOptions(overOptionsClone);
        Instances overNewData = Filter.useFilter(newData, smote);

        //            Main.logging("== New Data After Over Sampling: ===\n" + overNewData.toSummaryString());
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                new FileOutputStream(Main.OrangeProcessedDSHome + "/afterOverSampling.arff")))) {
            writer.write(overNewData.toString());
        }

    } catch (Exception ex) {
        Logger.getLogger(DataSetPair.class.getName()).log(Level.SEVERE, null, ex);
    }
}