获取 Weka 分类器结果
Get Weka Classifier Results
我是 Weka 的新手,正在尝试 运行 csv 数据文件上的分类器。我可以通过 classifier.toString()
、evaluation.toSummaryString()
、evaluation.toMatrixString()
方法以字符串形式获取结果来打印结果。
但是我的客户的要求是return json 对象中的变量值,而不是Weka 给出的输出格式。我们能否分别获取所有变量值,以便我可以将它们设置为我的自定义模型和 return 即 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
我可以单独读取上面的名称值对,而不是将它们放在字符串中吗?
您可以直接从评估对象中提取您感兴趣的大部分值。我不确定 "Coverage of cases" 和 "mean rel. region"。剩下的可以按如下方式完成:
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();
我是 Weka 的新手,正在尝试 运行 csv 数据文件上的分类器。我可以通过 classifier.toString()
、evaluation.toSummaryString()
、evaluation.toMatrixString()
方法以字符串形式获取结果来打印结果。
但是我的客户的要求是return json 对象中的变量值,而不是Weka 给出的输出格式。我们能否分别获取所有变量值,以便我可以将它们设置为我的自定义模型和 return 即 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
我可以单独读取上面的名称值对,而不是将它们放在字符串中吗?
您可以直接从评估对象中提取您感兴趣的大部分值。我不确定 "Coverage of cases" 和 "mean rel. region"。剩下的可以按如下方式完成:
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();