我在找出如何在 Java 代码中使用 WEKA 过滤器时遇到问题。我已经查找了帮助,但由于我使用的是 WEKA 3.8.5 ,它似乎有点过时了。我正在做3测试。测试 1:无过滤器,测试 2:weka.filters.supervised.instance.SpreadSubsample -M 1.0 和测试 3:weka.filters.supervised.instance.Resample -B 1.0 -Z 130.3。
如果我的研究是正确的,我应该像这样导入过滤器。现在我迷失了“-M 1.0”用于SpreadSample(我的抽样测试)和“-B 1.0 -Z 130.3”。重新采样(我的过采样测试)。
import weka.classifiers.trees.J48;
import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.supervised.instance.Resample;
import weka.filters.supervised.instance.SpreadSubsample;
我在下面编码了测试 1(我的无过滤器测试)
import java.io.FileReader;
import java.util.Random;
import weka.classifiers.Evaluation;
import weka.classifiers.trees.J48;
import weka.core.Instances;
public class Fraud {
public static void main(String args[])
{
try {
// Creating J48 classifier for the tree
J48 j48Classifier = new J48();
// Setting the path for the dataset
String FraudDataset = "C:\\Users\\Owner\\Desktop\\CreditCard\\CreditCard.arff";
BufferedReader bufferedReader
= new BufferedReader(
new FileReader(FraudDataset));
// Creating the data set instances
Instances datasetInstances
= new Instances(bufferedReader);
datasetInstances.setClassIndex(
datasetInstances.numAttributes() - 1);
Evaluation evaluation
= new Evaluation(datasetInstances);
// Cross Validate Model. 10 Folds
evaluation.crossValidateModel(
j48Classifier, datasetInstances, 10,
new Random(1));
System.out.println(evaluation.toSummaryString(
"\nResults", false));
}
// Catching exceptions
catch (Exception e) {
System.out.println("Error Occured!!!! \n"
+ e.getMessage());
}
System.out.print("DT Successfully executed.");
}
}
The results of my code is:
Results
Correctly Classified Instances 284649 99.9445 %
Incorrectly Classified Instances 158 0.0555 %
Kappa statistic 0.8257
Mean absolute error 0.0008
Root mean squared error 0.0232
Relative absolute error 24.2995 %
Root relative squared error 55.9107 %
Total Number of Instances 284807
DT Successfully executed.
有没有人知道如何将过滤器和我想要的过滤器设置添加到测试 2 和 3 的代码中?任何帮助将不胜感激。我将多次运行 3 次测试并比较结果。我想看看 3 中什么效果最好。