8

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.

Sagor Ali
  • 83
  • 3

1 Answers1

8

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
Reja
  • 898
  • 1
  • 9
  • 21