Java WEKA API - StratifiedRemoveFolds

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

Java WEKA API - StratifiedRemoveFolds

pavlos.ponos
Hello,

I have ~100 datasets in csv format and I'd like to apply Weka filter StratifiedRemoveFolds.
My code so far is:

CSVLoader loader = new CSVLoader();
loader.setSource(new File(datasetToBeProcessed.toString()));
Instances data = loader.getDataSet();

StratifiedRemoveFolds strRmvFolds = new StratifiedRemoveFolds();
strRmvFolds.setFold(fold);
strRmvFolds.setNumFolds(DatasetPreprocessing.numberOfFolds);
strRmvFolds.setSeed(0);
strRmvFolds.setInvertSelection(false);
strRmvFolds.setInputFormat(data);
data = StratifiedRemoveFolds.useFilter(data, strRmvFolds);

When I run this I get the following error message:

stratifyDatasetsWithWekaApi 
SEVERE: null
weka.core.UnassignedClassException: 
weka filters.supervised.instance.StratifiedRemoveFolds: 
Class attribute not set!

I've tried the following as well:

CSVLoader loader = new CSVLoader();
loader.setSource(new File(datasetToBeProcessed.toString()));
Instances data = loader.getDataSet();

String[] options = new String[4]; // initialize options
options[0] = "-S 0"; // seed number
options[1] = "-V"; // invert selection
options[2] = "-N 8"; // total number of folds
options[3] = "-F 1";  // current fold

strRmvFolds.setOptions(options);
strRmvFolds.setInputFormat(data);
data = StratifiedRemoveFolds.useFilter(data, strRmvFolds);

Error message is:

stratifyDatasetsWithWekaApi
SEVERE: null
java.lang.Exception: Illegal options: -S 0 -N 8 -F 1 

What am I doing wrong?

Thanks,

Pavlos

http://weka.sourceforge.net/doc.dev/weka/filters/supervised/instance/StratifiedRemoveFolds.html

-- 
*Pavlos K. Ponos*


My blog:
https://pavlosponosblog.wordpress.com

Public Linkedin profile:
www.linkedin.com/in/pavlos-k-ponos

-----------------------------------------------------------------------------
Don't send me files in the following formats:.doc(x),.xls(x),.ppt(x)
Instead, try and use Open Document formats: https://www.libreoffice.org
Save your money & use a Linux distro: http://distrowatch.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: Java WEKA API - StratifiedRemoveFolds

Eibe Frank-2
Administrator
The first error message is because the filter is a supervised one, so you need to specify which attribute is the class attribute.

After you have loaded the dataset, add the line

  data.setClassIndex(data.numAttributes() - 1);

This will set the class attribute to be the last attribute in your data.

The problem with the second variant is that you cannot have spaces in the individual array elements.

It’s simpler to use

  String[] options = weka.core.Utils.splitOptions("-S 0 -V -N 8 -F 1");

Cheers,
Eibe

> On 4/02/2019, at 7:23 AM, pavlos.ponos <[hidden email]> wrote:
>
> Hello everybody,
>
> I have ~100 datasets in csv format and I'd like to apply Weka filter
> StratifiedRemoveFolds.
> My code so far is:
>
> CSVLoader loader = new CSVLoader();
> loader.setSource(new File(datasetToBeProcessed.toString()));
> Instances data = loader.getDataSet();
>
> StratifiedRemoveFolds strRmvFolds = new StratifiedRemoveFolds();
> strRmvFolds.setFold(fold);
> strRmvFolds.setNumFolds(DatasetPreprocessing.numberOfFolds);
> strRmvFolds.setSeed(0);
> strRmvFolds.setInvertSelection(false);
> strRmvFolds.setInputFormat(data);
> data = StratifiedRemoveFolds.useFilter(data, strRmvFolds);
> When I run this I get the following error message:
>
> stratifyDatasetsWithWekaApi
> SEVERE: null
> weka.core.UnassignedClassException:
> weka filters.supervised.instance.StratifiedRemoveFolds:
> Class attribute not set!
>
> I've tried the following as well:
>
> CSVLoader loader = new CSVLoader();
> loader.setSource(new File(datasetToBeProcessed.toString()));
> Instances data = loader.getDataSet();
>
> String[] options = new String[4]; // initialize options
> options[0] = "-S 0"; // seed number
> options[1] = "-V"; // invert selection
> options[2] = "-N 8"; // total number of folds
> options[3] = "-F 1";  // current fold
>
> strRmvFolds.setOptions(options);
> strRmvFolds.setInputFormat(data);
> data = StratifiedRemoveFolds.useFilter(data, strRmvFolds);
>
> Error message is:
>
> stratifyDatasetsWithWekaApi
> SEVERE: null
> java.lang.Exception: Illegal options: -S 0 -N 8 -F 1
>
> What am I doing wrong?
>
> Thanks,
> Pavlos
>
> http://weka.sourceforge.net/doc.dev/weka/filters/supervised/instance/StratifiedRemoveFolds.html
>
>
>
>
> --
> 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