我是 Weka 的新手,并尝试在csv数据文件上运行分类器。我可以通过从classifier.toString()
,evaluation.toSummaryString()
,evaluation.toMatrixString()
方法获取字符串来打印结果。
但我的客户要求是返回json对象中的变量值,而不是Weka给出的输出格式。我们可以单独获取所有变量值,以便我可以将它们设置为我的自定义模型并将其作为json返回。
e.g. evaluationSummaryString=
Correctly Classified Instances 4 28.5714 %
Incorrectly Classified Instances 10 71.4286 %
Kappa statistic -0.0769
Mean absolute error 0.4722
Root mean squared error 0.6514
Relative absolute error 101.9709 %
Root relative squared error 132.1523 %
Coverage of cases (0.95 level) 50 %
Mean rel. region size (0.95 level) 45.2381 %
Total Number of Instances 14
我是否可以单独读取上面的名称值对,而不是将它们包含在字符串中。
答案 0 :(得分:3)
您可以直接从评估对象中提取您感兴趣的大多数值。我不确定“案件覆盖范围”和“平均相关区域”。其余的可以按如下方式完成:
Instances train = // load train instances ...
Instances test = // load test instances ...
// build and evaluate a model
J48 classifier = new J48();
classifier.buildClassifier(train);
Evaluation eval = new Evaluation(train);
eval.evaluateModel(classifier, test);
// extract the values of interest
double numberCorrect = eval.correct();
double numberIncorrect = eval.incorrect();
double pctCorrect = eval.pctCorrect();
double pctIncorrect = eval.pctIncorrect();
double Kappa = eval.kappa();
double MeanAbsoluteError = eval.meanAbsoluteError();
double RootMeanSquaredError = eval.rootMeanSquaredError();
double RelativeAbsoluteError = eval.relativeAbsoluteError();
double RootRelativeSquaredError = eval.rootRelativeSquaredError();
double TotalNumberOfInstances = eval.numInstances();