1

在 WEKA 中,我可以很容易地从混淆矩阵中找到 TP 率和真实分类实例总数,但是有没有办法查看 tp 和/或 tn 的确切数量?

你知道在 matlab-anfis 中找到这些值的任何方法吗?

4

1 回答 1

1

由于您提到了 MATLAB,我假设您正在使用 Weka 库的Java API以编程方式构建分类器。

在这种情况下,您可以使用weka.classifiers.Evaluation类评估模型,该类提供各种统计信息。

假设您已经weka.jar在 java 类路径上有文件(请参阅javaaddpath函数),下面是 MATLAB 中的示例:

%# data
fName = 'C:\Program Files\Weka-3-7\data\iris.arff';
loader = weka.core.converters.ArffLoader();
loader.setFile( java.io.File(fName) );
data = loader.getDataSet();
data.setClassIndex( data.numAttributes()-1 );

%# classifier
classifier = weka.classifiers.trees.J48();
classifier.setOptions( weka.core.Utils.splitOptions('-C 0.25 -M 2') );
classifier.buildClassifier( data );

%# evaluation
evl = weka.classifiers.Evaluation(data);
pred = evl.evaluateModel(classifier, data, {''});

%# display
disp(classifier.toString())
disp(evl.toSummaryString())
disp(evl.toClassDetailsString())
disp(evl.toMatrixString())

%# confusion matrix and other stats
cm = evl.confusionMatrix();

%# number of TP/TN/FP/FN with respect to class=1 (Iris-versicolor)
tp = evl.numTruePositives(1);
tn = evl.numTrueNegatives(1);
fp = evl.numFalsePositives(1);
fn = evl.numFalseNegatives(1);

%# class=XX is a zero-based index which maps to the following class values
classValues = arrayfun(@(k)char(data.classAttribute.value(k-1)), ...
    1:data.classAttribute.numValues, 'Uniform',false);

输出:

J48 pruned tree
------------------

petalwidth <= 0.6: Iris-setosa (50.0)
petalwidth > 0.6
|   petalwidth <= 1.7
|   |   petallength <= 4.9: Iris-versicolor (48.0/1.0)
|   |   petallength > 4.9
|   |   |   petalwidth <= 1.5: Iris-virginica (3.0)
|   |   |   petalwidth > 1.5: Iris-versicolor (3.0/1.0)
|   petalwidth > 1.7: Iris-virginica (46.0/1.0)

Number of Leaves  :     5

Size of the tree :  9


Correctly Classified Instances         147               98      %
Incorrectly Classified Instances         3                2      %
Kappa statistic                          0.97  
Mean absolute error                      0.0233
Root mean squared error                  0.108 
Relative absolute error                  5.2482 %
Root relative squared error             22.9089 %
Coverage of cases (0.95 level)          98.6667 %
Mean rel. region size (0.95 level)      34      %
Total Number of Instances              150     

=== Detailed Accuracy By Class ===

                 TP Rate  FP Rate  Precision  Recall   F-Measure  MCC      ROC Area  PRC Area  Class
                 1.000    0.000    1.000      1.000    1.000      1.000    1.000     1.000     Iris-setosa
                 0.980    0.020    0.961      0.961    0.961      0.955    0.990     0.969     Iris-versicolor
                 0.960    0.010    0.980      0.980    0.980      0.955    0.990     0.970     Iris-virginica
Weighted Avg.    0.980    0.010    0.980      0.980    0.980      0.970    0.993     0.980     

=== Confusion Matrix ===

  a  b  c   <-- classified as
 50  0  0 |  a = Iris-setosa
  0 49  1 |  b = Iris-versicolor
  0  2 48 |  c = Iris-virginica
于 2013-03-21T00:02:58.280 回答