gpt4 book ai didi

matlab - 在 weka 中查找真阳性的确切数量

转载 作者:行者123 更新时间:2023-11-30 09:13:30 25 4
gpt4 key购买 nike

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

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

最佳答案

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

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

假设您的 java 类路径上已有 weka.jar 文件(请参阅 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

关于matlab - 在 weka 中查找真阳性的确切数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15535546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com