SMOTE filter cannot handle numeric class

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

SMOTE filter cannot handle numeric class

lp77
I am using the SMOTE filter to sample several datasets. However, on a dataset
titled "eclipse", I get the following error when I use the SMOTE filter:
weka.filters.supervised.instance.SMOTE: Cannot handle numeric class! I need
to use the SMOTE sampling technique for these datasets, so I was wondering
if there is any fix for this? Unfortunately, the file is too large to post,
but I have condensed the file to just the attributes, hoping it may give
some insight as to why I have this problem.

Thanks.

Arff File:
eclipseMin.arff <http://weka.8497.n7.nabble.com/file/t6754/eclipseMin.arff>  



--
Sent from: http://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: SMOTE filter cannot handle numeric class

Eibe Frank-2
Administrator
WEKA’s SMOTE can only deal with nominal class attributes. The only way I can see is something like this:

  java weka.Run .RegressionByDiscretization -W .MultiClassClassifier -t ~/datasets/numeric/hungarian.arff -- -W .FilteredClassifier -- -F .SMOTE -W .J48

This will discretise the target to enable application of SMOTE.

Cheers,
Eibe

> On 3/02/2019, at 12:59 PM, lp77 <[hidden email]> wrote:
>
> I am using the SMOTE filter to sample several datasets. However, on a dataset
> titled "eclipse", I get the following error when I use the SMOTE filter:
> weka.filters.supervised.instance.SMOTE: Cannot handle numeric class! I need
> to use the SMOTE sampling technique for these datasets, so I was wondering
> if there is any fix for this? Unfortunately, the file is too large to post,
> but I have condensed the file to just the attributes, hoping it may give
> some insight as to why I have this problem.
>
> Thanks.
>
> Arff File:
> eclipseMin.arff <http://weka.8497.n7.nabble.com/file/t6754/eclipseMin.arff>  
>
>
>
> --
> Sent from: http://weka.8497.n7.nabble.com/
> _______________________________________________
> Wekalist mailing list
> Send posts to: [hidden email]
> To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: SMOTE filter cannot handle numeric class

lp77
How would I apply that line to my code? Here is what I have right now:

File:
public class SMOTESamp extends SMOTE{
   public static void main (String[] args) {
         
           for(int i = 1; i < 101; i++) {
         
           try{

           Instances data = DataSource.read("/Users/lp77/Desktop/eclipse.arff");
//Dataset
 
           int cIdx=data.numAttributes()-1;
           data.setClassIndex(cIdx);
           
           SMOTE smote=new SMOTE();  //create object of SMOTE

           
           smote.setInputFormat(data);

           //System.out.println("yup");
           Instances data_smote = Filter.useFilter(data, smote); //Apply SMOTE on
Dataset

           //System.out.println("SMOTE rocks!");
           OutputStream out = new
FileOutputStream("/Users/lp77/Desktop/eclipseSMOTE" + i + ".arff");
       out.write(data_smote.toString().getBytes());
       out.close();
           }

           catch (Exception e) {

           e.printStackTrace();

           }
       }
   }
}




--
Sent from: http://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: SMOTE filter cannot handle numeric class

Eibe Frank-3
Below is a Groovy script that shows how to set up the command-line in code.

Cheers,
Eibe

// Load dataset and set the class index
data = (new weka.core.converters.ConverterUtils.DataSource("/Users/eibe/datasets/numeric/quake.arff")).getDataSet()
data.setClassIndex(data.numAttributes() - 1)

// Load all packages so that SMOTE is loaded
weka.core.WekaPackageManager.loadPackages(false, false, false)

// Implementation of .RegressionByDiscretization -W .MultiClassClassifier -- -W .FilteredClassifier -- -F .SMOTE -W .J48
smote = weka.core.Utils.forName("weka.filters.supervised.instance.SMOTE").newInstance() // SMOTE is in a package so we need to use reflection
j48 = new weka.classifiers.trees.J48()
fcc = new weka.classifiers.meta.FilteredClassifier()
fcc.setFilter(smote)
fcc.setClassifier(j48)
mcc = new weka.classifiers.meta.MultiClassClassifier()
mcc.setClassifier(fcc)
rbd = new weka.classifiers.meta.RegressionByDiscretization()
rbd.setClassifier(mcc)

rbd.buildClassifier(data)

print(rbd)


On Sat, Feb 9, 2019 at 9:44 AM lp77 <[hidden email]> wrote:
How would I apply that line to my code? Here is what I have right now:

File:
public class SMOTESamp extends SMOTE{
   public static void main (String[] args) {

           for(int i = 1; i < 101; i++) {

           try{

           Instances data = DataSource.read("/Users/lp77/Desktop/eclipse.arff");
//Dataset

           int cIdx=data.numAttributes()-1;
           data.setClassIndex(cIdx);

           SMOTE smote=new SMOTE();  //create object of SMOTE


           smote.setInputFormat(data);

           //System.out.println("yup");
           Instances data_smote = Filter.useFilter(data, smote); //Apply SMOTE on
Dataset

           //System.out.println("SMOTE rocks!");
           OutputStream out = new
FileOutputStream("/Users/lp77/Desktop/eclipseSMOTE" + i + ".arff");
       out.write(data_smote.toString().getBytes());
       out.close();
           }

           catch (Exception e) {

           e.printStackTrace();

           }
       }
   }
}




--
Sent from: http://weka.8497.n7.nabble.com/
_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html

_______________________________________________
Wekalist mailing list
Send posts to: [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html