我已经从这里安装了“Matlab Weka Interface” 。我使用 BayesNet 的代码如下,但它会引发异常。请帮助我如何通过选项。
代码:
try
classifierNo=classifierNo+1;
wekaClassifierName = 'bayes.BayesNet';
wekaClassifierConfig = {'-D -Q weka.classifiers.bayes.net.search.local.K2 -- -P 1 -S BAYES -E weka.classifiers.bayes.net.estimate.SimpleEstimator -- -A 0.5'};
for i = 1:10
test = (indices == i);
train = ~test;
testSize = sum(test);
if testOriginal==0
train = [num2cell(mskMat(train,:)),irisLabels(train,:)];
test = [num2cell(global_origMat(test,:)),irisLabels(test,:)];
%Convert to weka format
train = matlab2weka('iTrain',featureNames,train,classIndex);
test = matlab2weka('iTest',featureNames,test);
%Train the classifier
nb = trainWekaClassifier(train,wekaClassifierName,wekaClassifierConfig);
%Test the classifier
predicted = wekaClassify(test,nb);
%The actual class labels (i.e. indices thereof)
actual = test.attributeToDoubleArray(classIndex-1);
correctRate = sum(actual == predicted)/testSize;
else
train = [num2cell(global_origMat(train,:)),irisLabels(train,:)];
test = [num2cell(global_origMat(test,:)),irisLabels(test,:)];
%Convert to weka format
train = matlab2weka('iTrain',featureNames,train,classIndex);
test = matlab2weka('iTest',featureNames,test);
%Train the classifier
nb = trainWekaClassifier(train,wekaClassifierName,wekaClassifierConfig);
%Test the classifier
predicted = wekaClassify(test,nb);
%The actual class labels (i.e. indices thereof)
actual = test.attributeToDoubleArray(classIndex-1);
correctRate = sum(actual == predicted)/testSize;
end
end
fprintf ('%f \n\t\t\t\t\t\t',correctRate);
sumCorrect(classifierNo)=sumCorrect(classifierNo)+correctRate;
repeatClassifier(classifierNo) = repeatClassifier(classifierNo) + 1;
end
错误如下:
使用 weka.classifiers.bayes.BayesNet/setOptions 时出错 发生 Java 异常: java.lang.Exception:非法选项:-D -Q weka.classifiers.bayes.net.search.local.K2 -- -P 1 -S BAYES -E weka.classifiers.bayes.net.estimate.SimpleEstimator -- -A 0.5 在 weka.core.Utils.checkForRemainingOptions(Utils.java:482) 在 weka.classifiers.bayes.BayesNet.setOptions(BayesNet.java:510)"