我需要找到训练错误或错误(D)并测试错误或错误。
假设,为了找到错误,我们使用公式:错误分类的实例/总实例然后找到错误(D),我们使用错误(s)+-confidenceInterval(sqrt(错误(s(1-错误(s)/n)) ))
这里 n= 实例总数
现在我怎样才能找到错误分类的实例?是否与使用 weka 的评估类评估模型可以找到的错误分类实例相同?请告诉我
代码:
import weka.classifiers.evaluation.Evaluation;
import weka.classifiers.trees.J48;
import weka.classifiers.trees.j48.ClassifierTree;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
@SuppressWarnings("unused")
public class J48Tree {
public static void main(String[] args) throws Exception {
//load dataset
DataSource trainsource = new DataSource(".//training data.arff");
DataSource testsource = new DataSource(".//test data.arff");
Instances dataset=trainsource.getDataSet();
Instances datatestset=testsource.getDataSet();
//set class index to the last attribute
dataset.setClassIndex(dataset.numAttributes()-1);
datatestset.setClassIndex(dataset.numAttributes()-1);
//create classifier
J48 tree = new J48();
//using an unpruned J48
tree.setUnpruned(true);
//build the classifier
tree.buildClassifier(dataset);
// evaluate classifier and print some statistics
Evaluation eval = new Evaluation(dataset);
eval.evaluateModel(tree, datatestset);
System.out.println(eval.toSummaryString("\nResults\n======\n", true));
} }
输出:
结果
Correctly Classified Instances 540 22.2772 %
Incorrectly Classified Instances 1884 77.7228 %
Kappa statistic 0.0644
K&B Relative Info Score 78375.7967 %
K&B Information Score 1912.8906 bits 0.7891 bits/instance
Class complexity | order 0 7268.6047 bits 2.9986 bits/instance
Class complexity | scheme 725668.4216 bits 299.3682 bits/instance
Complexity improvement (Sf) -718399.8169 bits -296.3696 bits/instance
Mean absolute error 0.2186
Root mean squared error 0.3897
Relative absolute error 91.6895 %
Root relative squared error 109.0212 %
Total Number of Instances 2424