I am trying to build classification model using Java Weka API. My training dataset have class imbalance problems. For this reason, I want to use SMOTE to reduce class imbalance problem. But, I do not know how to use it in Java Weka API.


Welcome to the community.

You can use the following code:

import weka.filters.supervised.instance.SMOTE;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.filters.Filter;

Instances data = DataSource.read(".../file.arff"); //Dataset 

SMOTE smote=new SMOTE();  //create object of SMOTE
Instances data_smote = Filter.useFilter(data, smote); //Apply SMOTE on Dataset
  • $\begingroup$ Thanks for your support. I am trying to applying your code. $\endgroup$ – Sagor Ali Nov 6 '18 at 10:32
  • $\begingroup$ I am glad to hear that. $\endgroup$ – Rejaul Karim Dec 4 '18 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.