0

我已经从这里安装了“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)"
4

1 回答 1

0

该错误意味着您正在使用变量中的无效参数进行传递wekaClassifierConfig。我不熟悉这个包,所以我不知道哪个参数不好,我会先回到文档或一一删除参数,看看哪个参数导致错误。

于 2012-11-20T14:52:57.853 回答