0
我已經從here安裝了「Matlab Weka接口」。我使用BayesNet的代碼如下,但它引發異常。請幫助我如何通過選項。如何將參數傳遞給「Matlab Weka接口」
代碼:
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
的誤差如下:
Error using weka.classifiers.bayes.BayesNet/setOptions Java exception occurred: java.lang.Exception: Illegal options: -D -Q weka.classifiers.bayes.net.search.local.K2 -- -P 1 -S BAYES -E weka.classifiers.bayes.net.estimate.SimpleEstimator -- -A 0.5 at weka.core.Utils.checkForRemainingOptions(Utils.java:482) at weka.classifiers.bayes.BayesNet.setOptions(BayesNet.java:510)"
謝謝你的幫助。經過一些嘗試後我發現我必須拆分選項。但是這沒有記錄。再次感謝你。 – remo