8
$\begingroup$

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.

$\endgroup$

1 Answer 1

8
$\begingroup$

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
smote.setInputFormat(data);
Instances data_smote = Filter.useFilter(data, smote); //Apply SMOTE on Dataset
$\endgroup$
2
  • $\begingroup$ Thanks for your support. I am trying to applying your code. $\endgroup$
    – Sagor Ali
    Commented Nov 6, 2018 at 10:32
  • $\begingroup$ I am glad to hear that. $\endgroup$
    – Reja
    Commented Dec 4, 2018 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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